Solved

URL value extraction

Posted on 2007-04-02
5
153 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

856 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