Skip to content

Instantly share code, notes, and snippets.

@AdrianSchneider
Created October 15, 2013 18:29
Show Gist options
  • Save AdrianSchneider/6996309 to your computer and use it in GitHub Desktop.
Save AdrianSchneider/6996309 to your computer and use it in GitHub Desktop.
<?php
$content = file_get_contents('/etc/hosts');
foreach (array_filter(explode("\n", $content)) as $line) {
$parts = preg_split('/\s+/', $line);
if (count($parts) < 2 or !preg_match('/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/', $parts[0])) {
continue;
}
list($ip, $hostName) = $parts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment