Re: explode string at new line

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

 



Em Quarta 06 Junho 2007 02:50, Jim Lucas escreveu:
> Chris wrote:
> > Davi wrote:
> >> Em Terça 05 Junho 2007 23:52, heavyccasey@xxxxxxxxx escreveu:
> >>> That's exactly correct. Except I /think/ you should use "\n" instead of
> >>> '\n'.
> >>
> >> array explode ( string $delimiter, string $string [, int $limit] )
> >>
> >> So, I was wrong...
> >> The right way, probaly, is:
> >>
> >> $str=explode("\n",$_POST["my_text"]);
> >
> > If it's coming from a <textarea> you'll want to use "\r\n" because a
> > textarea uses both a carriage return (\r) and newline (\n) to separate.
> >
> > Otherwise each element of the array will have a \r on the end which may
> > end up causing you some issues later on.
>
> I was wondering about this, I seem to recall that window/mac/*nix all do
> it differently.
>
> http://www.sitepoint.com/forums/printthread.php?t=54074
>
> Line breaks
> People want to know how they can retain textarea line breaks in HTML.
> You should store text in the database in its original format (e.g. with
> just newlines) and then use nl2br() to convert newlines to HTML <br />
> tags on display (thanks to the people here for teaching me that :)).
> That's all good, except for one problem with nl2br(): it doesn't seem to
> convert \r newlines (edit: this has now been fixed in PHP 4.2.0).
>
> PHP Code:
> $txt = preg_replace('/\r\n|\r/', "\n", $txt);
>

Helped... =)

But... Why does it happen:

[code]

$object=mysql_fetch_object($result);

$texto = $object->texto;

$texto=preg_replace("/\r|\n/","",stripslashes($texto));
echo $texto;

[/code]

[output]

Teste
\r\nde formatação!
\r\nTudo funcionando...
\r\n

[/output]


I'm using stripslashse 'cause I'm getting the values from a DB.

Any kind of tip?

TIA


-- 
Davi Vidal
davividal@xxxxxxxxxxxxxxxx
davividal@xxxxxxxxx
--
"Religion, ideology, resources, land,
spite, love or "just because"...
No matter how pathetic the reason,
it's enough to start a war. "
--------------------------------------------------------
Por favor não faça top-posting, coloque a sua resposta abaixo desta linha.
Please don't do top-posting, put your reply below the following line.
--------------------------------------------------------

Attachment: pgp0vmjOjwfTM.pgp
Description: PGP signature


[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