View Full Version : Extracting a href and title out of this string

10-27-2009, 04:23 PM
Hi Guys,

I want to get the href and title out of this html code below..

<li class="images"><a href="www.something.com/firstpage/" title="title1"><span>7</span></a></li>

I set the html code as a string

$strContent= "<li class="images"><a href="www.something.com/firstpage/" title="title1"><span>7</span></a></li>";

and set up this funtion with the regular expression below

$strListMatches = '!<li class="images" href="(.*)" title="(.*)"><span>(.*)</span</a></li>!isU';

function getMatches($strMatch,$strContent)
return $objMatches;
return "";

i tryed this piece of code to print the title but it wont work.


Is there something wrong with the regular expression?

iv tryed this regular expression but it wont work :(

$strListMatches = '!<li class="images" href="(.*)" title="(.*)"><span>(.*)</span></a></li>!isU';

10-27-2009, 04:26 PM
Don't use .* unless you fully understand it. If you want to extract a quoted section, you should use ".*?" or "[^"]*"

Phil Jackson
10-27-2009, 04:45 PM