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?
Hot to convert text to html
Moderator: General Moderators
Re: Hot to convert text to html
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).
Code: Select all
abc<br>
defCode: Select all
abc<br><br>
defRe: Hot to convert text to html
Code: Select all
$temp="abc\ndef";
htmlentities($temp);
echo nl2br($temp);
<br/> is not getting displayed.
Re: Hot to convert text to html
Code: Select all
<?php
$temp="abc\ndef";
nl2br($temp);
htmlentities($temp);
echo nl2br($temp);
?>
Re: Hot to convert text to html
Try:
Code: Select all
$temp= nl2br("abc\ndef");
echo htmlentities($temp);
Re: Hot to convert text to html
You aren't assigning the values returned from the functions to $temp.swetha wrote:Hi,the above is what i did,but this doesnt seem to work.i still get the same outputCode: Select all
<?php $temp="abc\ndef"; nl2br($temp); htmlentities($temp); echo nl2br($temp); ?>