[PHP] File encoding is changed by php script
- Date: Sat, 4 Mar 2017 23:02:38 -0800
- From: Jeffry Killen <jekillen@xxxxxxxxxxx>
- Subject: [PHP] File encoding is changed by php script
I have a project that uses php script to write to a file.
The file is itself a php script file.
The source of the content to write to the file is a text area element
in an html page.
The file to write to ends up with lines separated by two line breaks
and the encoding is set to western latin.
I have to manually set the encoding to utf-8 in order of scripts to
match and replace \n\r or \n\n. Otherwise neither will match and
I can't remove the double line breaks.
\r will match and the platform I am running on is Mac OSX, but
I thought that \r line breaks were obsolete on Mac. And it doesn't
replace double line break with single line break.
The html page as source of content to write to the file may contain
edits to the content. The original content is sent back so script can
match and replace. With different encoding, the match won't happen.
I have been manually resetting the encoding and running a separate
script to remove all the double line breaks.
My question is:
How do I get php to leave the encoding of the file at utf-8.
I am using file_get_contents to read the file into a string that can be
processed by str_replace.
I am using file_put_contents to write to the file.
The contents of the file are used as source for records to
display in textarea in html page. This page is set to XHTML, utf-8
Thanks for time and attention;
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php