I’m using fopen and fwrite to edit the .htaccess file in wordpress. Although it works fine I have a user complaining that the encoding has been changed from us-ascii to ISO-8859. Any suggestions on how to prevent this?
One thing you can try is overwriting the content type header using PHP’s header() function, i have personally never seen it used like this before but it might be worth a shot.
<?php
// Overwrite the content-type using a header statement
header('Content-Type: text/html; charset=us-ascii');
// Your fopen/fwrite code here....
?>
Thanks Sgt. I had been thinking of that, however the code in question is a Wordpress plugin and the user is concerned with how the file is actually saved. I wouldn’t think this would fix the matter…
Why not force a blanket encoding via .htaccess?
AddDefaultCharset UTF-8
I must admit, I’m not entirely sure what your issue is though. If it’s the contents of the file, can you not utf8_encode the string prior to writing it?
Happy Birthday.
Thanks Anthony, I’m not entirely sure of the clients issue myself. The script uses fopen and fwrite to add lines to the .htaccess in a wordpress install. He’s been complaining to me that after the write his file changes in the filesystem from us-ascii to 8859-iso. Personally I can’t see what the issue is if it is being served up by apache without problems, but as I promised him I’m trying to see if I can figure out anymore. Perhaps there is an aspect of the inner workings of fopen that I’m missing.
I don’t think fwrite and such are encoding aware, nor dependent. You could however, try setting [fphp]mb_internal_encoding[/fphp] to see if that helps.
Other than that, I’m stumped.
Good suggestion. I’ll take a look. Thanks!