Jump to content

Text encoding of apache access log


supersheep7

Recommended Posts

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

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....

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.