Welcome! Log In Create A New Profile

Advanced

[PHP] File encoding is changed by php script

Posted by Jeffry Killen 
Jeffry Killen
[PHP] File encoding is changed by php script
March 05, 2017 08:10AM
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;
JK

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jeffry Killen
Re: [PHP] File encoding is changed by php script
March 05, 2017 09:20AM
> On Mar 4, 2017, at 11:02 PM, Jeffry Killen <[email protected]> wrote:
>
> 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 am sorry I was not swift enough to figure this out before I posted
this query. I had solve the same problem a few years ago and forgot.

I have to replace \r with \n, and then replace \n\n with \n.

Thanks for time and attention, anyway;
J



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sorry, only registered users may post in this forum.

Click here to login