DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

đoạn Code Bóc Tách Danh Sách Socks (ip/port) Từ File Nội Dung Sử Dụng Regex

  • submit to reddit
        đoạn code bóc tách danh sách socks (ip/port) từ file nội dung sử dụng regex

$content = file_get_contents('myfile.htm');
//if(preg_match('/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\:[0-9]{1,5}/', $content, $match)) {
if(preg_match('/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3}):([0-9]{1,5})$/', $content, $match)) {
  foreach ($match as $result) {
    echo $result . "<br>\n";
} else {
  echo "Not an IP address!<br>\n";


Snippets Manager replied on Sun, 2011/08/07 - 5:20pm

why not just ues PHP's filter_var with FILTER_VALIDATE_IP and desired filter flag?