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
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>";
            }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.