kevinkhan Posted November 13, 2009 Share Posted November 13, 2009 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... Quote Link to comment Share on other sites More sharing options...
Mchl Posted November 13, 2009 Share Posted November 13, 2009 See Use Negated Character Sets Instead of the Dot here: http://www.regular-expressions.info/dot.html Quote Link to comment Share on other sites More sharing options...
salathe Posted November 13, 2009 Share Posted November 13, 2009 Please be more descriptive, "it doesnt seem to [work]" is of no use to anyone. What is the incorrect output/value that you are getting and how does it differ from what you are supposed to get? Quote Link to comment Share on other sites More sharing options...
kevinkhan Posted November 13, 2009 Author Share Posted November 13, 2009 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>"; } Quote Link to comment Share on other sites More sharing options...
cags Posted November 13, 2009 Share Posted November 13, 2009 Your code... if($objContactMatches != "") { echo "No List found or Invalid URL<br>"; } Spot the deliberate mistake. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.