Forum Moderators: coopster

Message Too Old, No Replies

Converting Windows New Lines to Unix?

         

Jacob or JaF

6:57 pm on Oct 24, 2007 (gmt 0)

10+ Year Member



Is there any way I can convert Windows new lines to Unix ones?
The reason is so that when someone posts something on a website using a Windows computer, when I edit the file on a Mac all the lines are properly computed.

Thank you,
Jacob

PHP_Chimp

7:42 pm on Oct 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can use str_replace [uk3.php.net]
There is an example on the page for a similar function.

eelixduppy

9:16 pm on Oct 24, 2007 (gmt 0)



I would probably use preg_replace because you aren't going to be sure what newline characters are used. So the following should work:

$pattern = "/[\r\n]*/";
[url=http://us2.php.net/preg_replace]preg_replace[/url]($pattern, "\n", $string);

coopster

1:25 pm on Oct 25, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You may want to use a different meta-character [php.net] though, to match at least 1 otherwise it is going to gobble up anything ...
$pattern = "/[\r\n]+/";