Use at own risk. Programs haven't been thoroughly tested.

function: extract_ipaddresses

Regex function to extract a ip addresses from a string Very usefull for parsing logfiles. Returns a clean array of ip addresses (if found)

Info

@author Kevin van Zonneveld
@version 0.7
@link http://kevin.vanzonneveld.net
@param (string) $data The haystack to search in

Example

Usage
print_r(extract_ipaddresses($log_buffer));

Outputs
Array(0=>127.0.0.1, 1=>192.168.0.1)

Source Code

download source
<?  
function extract_ipaddresses($data){
  
  $num="(25[0-5]|2[0-4]\d|[01]?\d\d|\d)";
  preg_match_all("/$num\\.$num\\.$num\\.$num/",$data,$match);
  return reset($match);
}
?>

Add comment

» Currently away on vacation. I can reply your message the 24th of July 2008. Please post anyway and check back then. Thank you!

for syntax highlighting

[CODE="Javascript"]
your_code_here();
[/CODE]

Replace "Javascript"
with "php", "text", etc.
code (to make sure you are not a spammer)

Comments

No comments. Be the first!