Re: Getting a 'newline' out of a string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2007-08-10 at 18:14 +0200, Faither wrote:
> Hey there!
> I'm kind of lost with how str_replace , preg_replace, ereg_replace or 
> even explode are handling a "\n"-ewline.
> 
> I have a text string from a form and am trying to replace the "\n" or 
> chr(10) or however you might call the newline with a simple html break tag.
> 
> If I use the replacing functions I get the <br>-tags where there are 
> newlines from the textarea of the form. BUT I still have the newlines 
> remain.

That extra newline is probably caused by a "\r" character as promoted by
the Windows operating system.

You could try the following:

<?php

    $string = str_replace( "\n", '<br />', $string );
    $string = str_replace( "\r", '', $string );

?>

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux