Jump to content

Extracting all IP's of a string


drisate

Recommended Posts

hey guys i need to extract all the IP's of a string and loop them for more operations but for some reason i only get the first one

 

<?php

$string = '80.37.14.13 80.37.14.14 80.37.14.15';
preg_match("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $string, $matches);

foreach ($matches as $ip){
    echo "$ip<br>";
}

?>

 

The string is not really seperated by spaces ... it can actualy be messy and have ips rapped arround a lot of code. The regex works because i do get the first one ...

 

What did i miss?

Link to comment
https://forums.phpfreaks.com/topic/257887-extracting-all-ips-of-a-string/
Share on other sites

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.