Jump to content

preg_match_all -> class="l">85.236.100.103 <img src="/i/launch.gif" title="Launc


scarhand

Recommended Posts

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

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
        )

)

Archived

This topic is now archived and is closed to further replies.

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