Jump to content

Simple Regular Expression Question


kevinkhan

Recommended Posts

Im trying to get a regular expression for this piece of html.

 

<p>Contact number: 021-4858400</p>

or

<p>Contact number: 023.8843822 / 087.6523303</p>

 

 

I taught this might work but it doesnt seem to

 

'!<p>Contact number:\s(.*)</p>!isU'

 

Does anybody know what i have done wrong?

 

Thanks for your help...

Link to comment
https://forums.phpfreaks.com/topic/181376-simple-regular-expression-question/
Share on other sites

ok iv set up this script and i get No List found or Invalid URL

 

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

        $strDetailContent = "<p>Contact number: 021-4858400</p>";
$strContactMatches = '!<p>Contact number:\s(.*)</p>!isU';
  					
  					$objContactMatches = getMatches($strContactMatches,$strDetailContent);
  					if($objContactMatches != "") 
            {
  		      echo "No List found or Invalid URL<br>";
  					}
  					else
  					{
            print "Number = ".trim($objContactMatches[1][0])."<br>";
            }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.