All welcome.
It is necessary to extract all ip addresses from the string using regexp and write to the file. But, the array obtained with regexp takes an awkward look, how can you alter this code so that all ip addresses are recorded?
$string = "127.0.0.1:8000 127.0.0.1:81 127.0.0.1:77 127.0.0.1:66"; preg_match_all("/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\:[0-9]{1,5})/", $string, $result); $res = ''; foreach($result as $key => $value) { $res .= $value[$key]."\r\n"; } file_put_contents('text.txt', $res);
(Only the first 2 IP addresses are recorded)
var_dump:
array(2) { [0]=> array(4) { [0]=> string(14) "127.0.0.1:8000" [1]=> string(12) "127.0.0.1:81" [2]=> string(12) "127.0.0.1:77" [3]=> string(12) "127.0.0.1:66" } [1]=> array(4) { [0]=> string(14) "127.0.0.1:8000" [1]=> string(12) "127.0.0.1:81" [2]=> string(12) "127.0.0.1:77" [3]=> string(12) "127.0.0.1:66" } }
Thank you in advance.