fullahimhard Posted June 3, 2009 Share Posted June 3, 2009 Hiyas, I am trying to pregmatch the telephone number the html code is: <tr class='attribute'><td class='attribute-label' valign='top'>Telephone: </td><td class='attribute-value'>9556856</td></tr> My preg_match uses: preg_match('|valign=\'top\'>Telephone: </td><td class=\'attribute-value\'>(.*?)</td></tr>|im', $result1, $match3); But it isnt picking anything up. Any ideas why? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/160789-broken-preg_match/ Share on other sites More sharing options...
Maq Posted June 3, 2009 Share Posted June 3, 2009 Picks it up for me. How are you displaying the matches? print_r($match3); Also, if you put your pattern in double quotes you won't need to escape all the inner single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/160789-broken-preg_match/#findComment-848593 Share on other sites More sharing options...
nrg_alpha Posted June 3, 2009 Share Posted June 3, 2009 My first choice would probably be DOM / XPath (there's always other ways to skin a cat), but if going the regex route, one method could be: Example: $str = "<tr class='attribute'><td class='attribute-label' valign='top'>Telephone: </td><td class='attribute-value'>9556856</td></tr>"; preg_match('#Telephone: </td><td[^>]+class=[\'"]attribute-value[\'"]>(\d+)</td>#i', $str, $match); echo $match[1]; // Output: 9556856 Granted, the (\d+) assumes that there are only consecutive digits for the value of that td tag. If you want to just match anything to make sure, that part of the pattern could be replaced with ([^<]+) instead Quote Link to comment https://forums.phpfreaks.com/topic/160789-broken-preg_match/#findComment-848648 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.