Re: regex problem

From: Date: Thu, 01 Jul 2004 22:17:04 +0000
Subject: Re: regex problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-189493@lists.php.net to get a copy of this message
On Thu, 1 Jul 2004 16:41:50 -0500, Josh Close <narshe@gmail.com> wrote: > > I'm trying to get a simple regex to work. Here is the test script I have. > > #!/usr/bin/php -q > <? > > $string = "hello\nworld\n"; > $string = preg_replace("/[^\r]\n/i","\r\n",$string); $string = preg_replace("/([^\r])\n/i","\\1\r\n",$string); You could also use forward look-aheads, but I don't remember how to do that right now. > $string = addcslashes($string, "\r\n"); > > print $string; > > ?> > > This outputs > > hell\r\nworl\r\n > > so it's removing the char before the \n also. > > I just want it to replace a lone \n with \r\n > > -Josh > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > !DSPAM:40e48327189276451316304! > > -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin--

« previous php.general (#189493) next »