Solved

URL value extraction

Posted on 2007-04-02
5
150 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
Comment Utility
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
Comment Utility
yes but my string can have more than 1 href.
0
 
LVL 48

Expert Comment

by:hernst42
Comment Utility
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
Comment Utility
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
Comment Utility
got it to display how i want it... thank you
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
The viewer will learn how to count occurrences of each item in an array.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now