Re: preg_replace ^M

From: Date: Thu, 06 Nov 2003 13:58:37 +0000
Subject: Re: preg_replace ^M
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-168716@lists.php.net to get a copy of this message
Those are \r characters from dos newline (\r\n). Generally they are not harmful and many editors can work with them without problems (vim). You can use some utility commands to convert to or from dos or unix newlines. Torsten Rosenberger wrote:
Hello i try to replace a string in a file but if i have linefeeds in the string the output file after the replacement has ^M carachters in in if the $replacements[] = "test"; has no \n in it all is OK $fp = fopen ("draft.html", "r"); $incont = fread ($fp,filesize("draft.html")); fclose ($fp);
$patterns[]     = "/\[CONTENT\]/";
$replacements[] = "test\nout"; $content = preg_replace ($patterns,$replacements,$incont); $fp = fopen ("out.html","w"); fputs ($fp, $content); fclose($fp); draft.html looks like: form method="post" [CONTENT] /form the out put get ugly ^M form method="post" ^M SERAVS toro^M ^M /form>^M BR/Torsten


« previous php.general (#168716) next »