chriswiegman — 2011-06-21T09:55:08-04:00 — #1
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?
chris_upjohn — 2011-06-21T10:15:12-04:00 — #2
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.
// Overwrite the content-type using a header statement
header('Content-Type: text/html; charset=us-ascii');
// Your fopen/fwrite code here....
chriswiegman — 2011-06-21T10:17:19-04:00 — #3
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....
anthonysterling — 2011-06-21T10:31:09-04:00 — #4
Why not force a blanket encoding via .htaccess?
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?
chriswiegman — 2011-06-22T16:38:18-04:00 — #5
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.
anthonysterling — 2011-06-22T17:10:41-04:00 — #6
I don't think fwrite and such are encoding aware, nor dependent. You could however, try setting mb_internal_encoding to see if that helps.
Other than that, I'm stumped.
chriswiegman — 2011-06-22T17:12:18-04:00 — #7
Good suggestion. I'll take a look. Thanks!