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); ?> Link to comment https://forums.phpfreaks.com/topic/171361-text-encoding-of-apache-access-log/ 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.... Link to comment https://forums.phpfreaks.com/topic/171361-text-encoding-of-apache-access-log/#findComment-903706 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? Link to comment https://forums.phpfreaks.com/topic/171361-text-encoding-of-apache-access-log/#findComment-905222 Share on other sites More sharing options...
supersheep7 Posted August 24, 2009 Author Share Posted August 24, 2009 Can anyone else help? Link to comment https://forums.phpfreaks.com/topic/171361-text-encoding-of-apache-access-log/#findComment-905438 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? Link to comment https://forums.phpfreaks.com/topic/171361-text-encoding-of-apache-access-log/#findComment-906038 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.