scarhand Posted November 27, 2008 Share Posted November 27, 2008 I am looking to match all occurances of this: class="l">85.236.100.103 <img src="/i/launch.gif" title="Launch"/></a></td><td>29060 where "85.236.100.103" could be any IP address, and "29060" could be any port. heres my code thats not working: <?php preg_match_all('|class="l">([0-9.]+) <img src="/i/launch.gif" title="Launch"/></a></td><td>([0-9]+)|', $content, $matches); ?> Link to comment https://forums.phpfreaks.com/topic/134487-preg_match_all-classl85236100103/ Share on other sites More sharing options...
ddrudik Posted November 27, 2008 Share Posted November 27, 2008 Your code works for me, maybe your real-world source is different than your sample: <pre> <?php $content='class="l">85.236.100.103 <img src="/i/launch.gif" title="Launch"/></a></td><td>29060 class="l">85.236.100.103 <img src="/i/launch.gif" title="Launch"/></a></td><td>29060 class="l">85.236.100.103 <img src="/i/launch.gif" title="Launch"/></a></td><td>29060'; preg_match_all('|class="l">([0-9.]+) <img src="/i/launch.gif" title="Launch"/></a></td><td>([0-9]+)|', $content, $matches); echo htmlentities(print_r($matches,true)); ?> output: Array ( [0] => Array ( [0] => class="l">85.236.100.103 <img src="/i/launch.gif" title="Launch"/></a></td><td>29060 [1] => class="l">85.236.100.103 <img src="/i/launch.gif" title="Launch"/></a></td><td>29060 [2] => class="l">85.236.100.103 <img src="/i/launch.gif" title="Launch"/></a></td><td>29060 ) [1] => Array ( [0] => 85.236.100.103 [1] => 85.236.100.103 [2] => 85.236.100.103 ) [2] => Array ( [0] => 29060 [1] => 29060 [2] => 29060 ) ) Link to comment https://forums.phpfreaks.com/topic/134487-preg_match_all-classl85236100103/#findComment-700318 Share on other sites More sharing options...
scarhand Posted November 27, 2008 Author Share Posted November 27, 2008 i had to escape the period. it works now. Link to comment https://forums.phpfreaks.com/topic/134487-preg_match_all-classl85236100103/#findComment-700465 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.