From: "Jeff Oien" <[EMAIL PROTECTED]>

> That almost works. The two \n in a row are on new lines.
> So it's
> \n
> \n
> intead of \n\n. If that makes any sense.
> Jeff Oien


No, that doesn't make any sense whatsoever :)

A \n *is* a new line. I can only guess you're getting confused because
there's \r's as well as \n's in the string. Try this:


<?php
    $str = "abc\r\ndefg\r\n\r\nxyzpqr\r\njklmno";
    $str = ereg_replace("([^\r\n])\r\n([^\r\n])", "\\1 \\2", $str);
    echo $str;
?>

Or alternatively:

<?php
    $str = "abc\r\ndefg\r\n\r\nxyzpqr\r\njklmno";
    $str = ereg_replace("\r", "", $str);
    $str = ereg_replace("([^\n])\n([^\n])", "\\1 \\2", $str);
    echo $str;
?>


A CR is a carriage return, a LF is a line feed or newline. \r = CR, \n = LF.
Unix files use only LF (\n) for new lines, whereas MS DOS/Windows uses CRLF
(\r\n) and Mac uses just CR (\r).


Cheers

Simon Garner



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to