Why is it taking the char before the [^\r] also?
-Josh
On Thu, 1 Jul 2004 15:17:04 -0700, Justin Patrin <[EMAIL PROTECTED]> wrote:
>
> On Thu, 1 Jul 2004 16:41:50 -0500, Josh Close <[EMAIL PROTECTED]> 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--
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php