Page 1 of 1
Hot to convert text to html
Posted: Tue Oct 14, 2008 3:19 am
by swetha
Hi,
im trying to convert text to html.
i used nl2br function,but this function only adds a new line
to the text whenever it encounters "/n":
i.e if the string is "abc\ndef"
and i give echo nl2br(abc\ndef"),then i get the following output:
abc
def
i need to get the following output:
abc<br>
def
how do i get this output?
Re: Hot to convert text to html
Posted: Tue Oct 14, 2008 3:28 am
by onion2k
Are you aware that...
in HTML is actually...
Run the text through nl2br() once, then through htmlentities(), and then put it through nl2br() a second time. Display that and you'll see the <br> tags (although they may actually be <br /> depending on which version of PHP you're running).
Re: Hot to convert text to html
Posted: Tue Oct 14, 2008 6:26 am
by swetha
Code: Select all
$temp="abc\ndef";
htmlentities($temp);
echo nl2br($temp);
tied the above .stilll i get the same output.
<br/> is not getting displayed.
Re: Hot to convert text to html
Posted: Tue Oct 14, 2008 6:51 am
by swetha
Code: Select all
<?php
$temp="abc\ndef";
nl2br($temp);
htmlentities($temp);
echo nl2br($temp);
?>
Hi,the above is what i did,but this doesnt seem to work.i still get the same output
Re: Hot to convert text to html
Posted: Tue Oct 14, 2008 6:53 am
by papa
Try:
Code: Select all
$temp= nl2br("abc\ndef");
echo htmlentities($temp);
Re: Hot to convert text to html
Posted: Tue Oct 14, 2008 9:24 am
by onion2k
swetha wrote:Code: Select all
<?php
$temp="abc\ndef";
nl2br($temp);
htmlentities($temp);
echo nl2br($temp);
?>
Hi,the above is what i did,but this doesnt seem to work.i still get the same output
You aren't assigning the values returned from the functions to $temp.