[SOLVED] preg_match - <a href>

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dstefani
Forum Contributor
Posts: 140
Joined: Sat Jan 11, 2003 9:34 am
Location: Meridian Idaho, USA

[SOLVED] preg_match - <a href>

Post by dstefani »

Hello,

If I kept searching I probably would eventually find my answer but I'm running out of time. I need to grab the link and the link text from an href.

IE:

Code: Select all

<a href="http://www.elverta.k12.ca.us/home/" target="content">Elverta Joint Elementary School District</a><br />
I'm using the example from the manual (preg_match) to get the domain, OK great, but I'm having trouble getting the label. 'Elverta Joint Elementary School District'.

Here's my test code:

Code: Select all

$handle = fopen("./yololinks.txt", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) &#123;
list($link) = $data;
preg_match("/^(<a href="http:\/\/)?(&#1111;^\/]+)/i", $link, $matches);
$host = $matches&#1111;2];

    
    print "$host<p>\n";
    
&#125;
fclose($handle);
What do I need to add to get the text between the <a></a> tags?

Thanks!

- dstefani
User avatar
dstefani
Forum Contributor
Posts: 140
Joined: Sat Jan 11, 2003 9:34 am
Location: Meridian Idaho, USA

Post by dstefani »

Should have waited!

Got it

Code: Select all

preg_match("/<a(.*)>(.*)<\/a>/i", $link, $matches);
$host = $matches&#1111;2];
Thanks for being there!!! :P
So I could talk to myself!

- dstefani :oops: :oops: :oops:
Post Reply