You are here: Re: Replace the CR/LF in a textarea by str_replace « PHP Programming Language « IT news, forums, messages
Re: Replace the CR/LF in a textarea by str_replace

Posted by Ivαn Sαnchez Ortega on 06/07/06 07:52

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Wayne wrote:

> $a = $_POST['txt_content']; # txt_content = This is a<CR><LF>Test
> $p = str_replace ("%0D%0A", "<br>", $a);

- From what language did you come from? "%0D%0A" is not a valid syntax to
specify ascii characters in a string. Please have a read:

http://es.php.net/manual/en/language.types.string.php#language.types.string.syntax.double

And, if you want to check for CR-LF, plus CR alone, plus LF alone, you may
want to pass an array to str_replace:

str_replace( array("\r\n","\r","\n") , '<br>' , $subject);

Alternatively:

str_replace( array("\0x0d\0x0a","\0x0d","\0x0a") , '<br>' , $subject);

Alternatively:

str_replace( array(chr(13).chr(10) , chr(13) , chr(10)) , '<br>' ,
$subject);

And, most important:

nl2br($subject);

- --
- ----------------------------------
IvΓ‘n SΓ‘nchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

http://acm.asoc.fi.upm.es/~mr/ ; http://acm.asoc.fi.upm.es/~ivan/
MSN:i_eat_s_p_a_m_for_breakfast@hotmail.com
Jabber:ivansanchez@jabber.org ; ivansanchez@kdetalk.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)

iD8DBQFEhoW/3jcQ2mg3Pc8RAn61AJoD2RxamjK7QTy80onOP9clKHMijgCfVKQt
uY/ZtXUSqrp9ek/vH5bttk4=
=U92G
-----END PGP SIGNATURE-----

 

Navigation:

[Reply to this 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

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация