On a Windows XP machine, I wanted to loop through a list of ip numbers and use ping -a to extract the domain names as strings. The loop worked fine. However, when I attempted to echo just the line containing the domain name, I hit a snag. The line endings in the text file are not real line endings. The split statement leaves you with just one array element. Does anyone know what character(s) the Pseudo-DOS in XP uses to end lines, i.e., what I should have used instead of "\n" in my split command?
Second, related question. In the old ASCII days, many programs let you feed a character into ORD or some similar function, and it returned the ASCII number. How would you do that in PHP? Would it be Unicode instead of ASCII?
<?php
for ($i = 0; $i <= 255; $i++)
{
$ip = "66.115.151.".$i;
`ping -a $ip >> domains.txt`;
echo "ping -a ".$ip."\n";
}
$filename = "C:\Documents and Settings\John\domains.txt";
$fh = fopen($filename, "r");
$contents = fread($fh, filesize($filename) );
fclose ($fh);
$line = split("\n", $contents);
# echo count($contents);
foreach ($line as $value)
{
if ( ereg( "pinging", $value) )
{
echo $value."\n";
}
}
?>