note 54748 added to function.str-replace

From: Date: Thu, 14 Jul 2005 10:22:45 +0000
Subject: note 54748 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-91948@lists.php.net to get a copy of this message
If you need to strip out newlines, then using a single str_replace() call is not portable, due to the difference between DOS/Win32, Mac and UNIX conventions. For portability try something like: <?php $x = 'My name is fred'; $x = str_replace("\n", "", $x); //UNIX $x = str_replace("\r\n", "", $x); //DOS $x = str_replace("\r", "", $x); //MAC ?> Alternativley, do it in one line with preg_replace: <?php $x = preg_replace('/\n|\r|(\r\n)/m', '', $x); ?> Apologies if someone already pointed this out. ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54748 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54748&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54748&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54748&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54748&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54748&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54748&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54748&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91948) next »