Reply to Re: Replace the CR/LF in a textarea by str_replace

Your name:

Reply:


Posted by Alan Little on 06/07/06 00:24

Carved in mystic runes upon the very living rock, the last words of
Wayne of comp.lang.php make plain:

> $a = $_POST['txt_content']; # txt_content = This is a<CR><LF>Test
> $p = str_replace ("%0D%0A", "<br>", $a);
>
> That is the above code that I am using, however, it is not picking up
> the CR/LF from the textarea.

Try $p = str_replace ("\r\n", "<br>", $a);

However, depending on what OS and/or browser your visitors use, a new
line character might be passed as CR, LF or CRLF. I usually do something
like:

$p = ereg_replace("\r\n?" "\n", $a);
$p = str_replace("\n", '<BR>', $p);

The first line makes sure they're all LFs before converting them to BRs.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация