Solved

URL value extraction

Posted on 2007-04-02
5
155 Views
Last Modified: 2007-04-02
ive got a string like this:

$string = 'Clearly describe your <a href="">question</a> or problem, along with <a href="">specific information</a> such as <a href="">product names</a>, OS, and any error messages.';

how can i extract all the values between <a></a> from the above string?  for example the values from the above string should be: question, specific information & product names.
0
Comment
Question by:ellandrd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 18834929
use preg_match_all for this like:
preg_match_all('/<a[^>]+>(.*?)<\/a>/', $string, $m);
$m[1] will be an array with the requested information
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18834958
yes but my string can have more than 1 href.
0
 
LVL 48

Expert Comment

by:hernst42
ID: 18834979
yes and the example extracts them all, Haven't you tried it or do you get results which sould not be in the result?
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18835044
my results are:

Array ( [0] => Array ( [0] => Google  ) [1] => Array ( [0] => Google ) )

so in order to print out info i have to use: print_r();
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18835053
got it to display how i want it... thank you
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question