Page 1 of 1

[SOLVED] preg_match - <a href>

Posted: Wed Jan 19, 2005 5:08 pm
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

Posted: Wed Jan 19, 2005 5:16 pm
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: