...

View Full Version : Regular Expression Problem



kevinkhan
11-02-2009, 02:03 PM
How come im not getting any results back for this code?



function getMatches($strMatch,$strContent) {
if(preg_match_all($strMatch,$strContent,$objMatches)){
return $objMatches;
}
return "";
}

$strContent = "<li class="tel"><strong>Tel:&nbsp;</strong><span><!-- sphoneid telnr="+353 (021)4501172" fileas="Abbey Business & Communications" -->(021)4501172<!-- sphoneid --></span></li>";
$strMatch = "<li class=\"tel\"><strong>Tel:&nbsp;</strong><span><!-- sphoneid telnr=\"(.*)\" fileas=\"(.*)\" -->(.*)<!-- sphoneid --></span></li>isU";

getMatches($strMatch,$strContent);


if ($objMatches !=0)
{

echo '<pre>';print_r ($objMatches);echo '</pre>';
}

else
{
echo "no matches";
}

Phil Jackson
11-02-2009, 02:52 PM
#<\!--\ssphoneid\stelnr=\"([^\"]*)\"\sfileas=\"([^\"]*)\"\s-->([^<]*)<\!--\ssphoneid\s-->#is



Array
(
[0] => <!-- sphoneid telnr="+353 (021)4501172" fileas="Abbey Business & Communications" -->(021)4501172<!-- sphoneid -->
[1] => +353 (021)4501172
[2] => Abbey Business & Communications
[3] => (021)4501172
)

abduraooft
11-02-2009, 03:03 PM
$strContent = "<li class="tel"><strong>Tel:&nbsp;</strong><span><!-- sphoneid telnr="+353 (021)4501172" fileas="Abbey Business & Communications" -->(021)4501172<!-- sphoneid --></span></li>";
$strMatch = "<li class=\"tel\"><strong>Tel:&nbsp;</strong><span><!-- sphoneid telnr=\"(.*)\" fileas=\"(.*)\" -->(.*)<!-- sphoneid --></span></li>isU";
Your code has some syntax errors. Turn on error reporting, if you haven't done.

Phil Jackson
11-02-2009, 03:19 PM
hints towards the blue words abduraooft's quote

kevinkhan
11-02-2009, 04:12 PM
#<\!--\ssphoneid\stelnr=\"([^\"]*)\"\sfileas=\"([^\"]*)\"\s-->([^<]*)<\!--\ssphoneid\s-->#is



Array
(
[0] => <!-- sphoneid telnr="+353 (021)4501172" fileas="Abbey Business & Communications" -->(021)4501172<!-- sphoneid -->
[1] => +353 (021)4501172
[2] => Abbey Business & Communications
[3] => (021)4501172
)


Works like a charm..

Thanks a mill....



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum