Solved

URL value extraction

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

831 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