supersheep7 Posted August 22, 2009 Share Posted August 22, 2009 Hi, PHP newbie here. I'm trying to write a short script that greps through an apache access log, searching for a given string, and printing out all lines that include that string. Everything works fine, except that every '?' in the apache log is replaced by a when printed. When I open the apache log in vi, I see question marks as normal, not the weird mojibake. It comes out as in firefox, | in IE, and just get skipped in Chrome. I'm not even completely certain that it's a php issue, but that's my intuition. My php code looks like this: <?php $handle = open('grep stringtofind /path/to/apache/logs/access', 'r'); $output = fread($handle, 1000000); pclose($handle); echo($output); ?> Quote Link to comment Share on other sites More sharing options...
oni-kun Posted August 22, 2009 Share Posted August 22, 2009 Sounds weird, Try doing something like so: <?php $handle = open('grep stringtofind /path/to/apache/logs/access', 'r'); $output = utf8_encode(fread($handle, 1000000)); pclose($handle); echo($output); ?> And set a meta tag to show it's UTF-8. Your log could be in iso-latin1, your page may think it's utf, and your php doesn't know what's going on, so your browser will display the ? incorrectly in utf as latin-1 etc.... Quote Link to comment Share on other sites More sharing options...
supersheep7 Posted August 24, 2009 Author Share Posted August 24, 2009 Thanks oni-kun. I tried your solution, but to no avail (it produces the same output as my original code). Any other ideas on how to mess with the encoding? Quote Link to comment Share on other sites More sharing options...
supersheep7 Posted August 24, 2009 Author Share Posted August 24, 2009 Can anyone else help? Quote Link to comment Share on other sites More sharing options...
supersheep7 Posted August 25, 2009 Author Share Posted August 25, 2009 Sorry to keep bumping, but does anyone know what's wrong here? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.