hi,
following on from something the other day I was having trouble with I need help with the this please 🙂
I currently have the following string. (split into two lines when output on this board)
$string2 = "This is <a href=\"http://www.hotmail.com\">Hotmail</a> the description
part <a href=\"http://www.inlandrevenue.com\">Inland Revenue</a> here is another part of the description text again";
and I then have a regular expression that gets out all of the web links held in the URL. The code for this is as such
preg_match_all("|href=\"?([^\"' >]+)|i", $string2, $matches);
echo "<p></p>";
echo count($matches[0]) . "<br>";
for ($i=0; $i< count($matches[0]); $i++) {
echo "matched: ".$matches[1][$i]."<br>";
}
The output from this, looks like....
2
matched: [url]http://www.hotmail.com[/url]
matched: [url]http://www.inlandrevenue.com[/url]
The problem is that I also need the text from the link. So I need 'Hotmail' and 'Inland Revenue'. I can't get my head round regular expressions at all.
edited
I don't have to get them all out at the same time either. I'd probably prefer to get out the links with one match and the text with another regular expression.
🙂
Thanks