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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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