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... Link to comment https://forums.phpfreaks.com/topic/181376-simple-regular-expression-question/ 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 Link to comment https://forums.phpfreaks.com/topic/181376-simple-regular-expression-question/#findComment-956769 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? Link to comment https://forums.phpfreaks.com/topic/181376-simple-regular-expression-question/#findComment-956788 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>"; } Link to comment https://forums.phpfreaks.com/topic/181376-simple-regular-expression-question/#findComment-956796 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. Link to comment https://forums.phpfreaks.com/topic/181376-simple-regular-expression-question/#findComment-956800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.