Page 1 of 1

print text without html

Posted: Thu Sep 28, 2006 3:29 pm
by keveh
I was wondering if it was possible for php to print text from a database without the html being included, yet still using line breaks?

for example, if i stored the following in a database as text:

This is some text.

new line

<a href="index.html">link</a>


and used

Code: Select all

echo (nl2br($text));
to print it, it would appear like so:

This is some text.

new line

link



So is there a way to print it as it was entered, so that somebody posting a comment can't use HTML, but still have the line breaks for each new line?[/url]

Posted: Thu Sep 28, 2006 3:31 pm
by a94060
maybe soemthing like

Code: Select all

strip_tags(' $string',<br>);

Posted: Thu Sep 28, 2006 3:44 pm
by keveh
Thanks, I did it by using the following:

Code: Select all

nl2br(strip_tags($comments[comText], '<br>'))

Posted: Thu Sep 28, 2006 3:49 pm
by a94060
what are you using the nl2br for? are you entering things into the database like

Code: Select all

"This is a test\n to see if <font color="red">\n i can do this</font>"
Or are you doing something like

Code: Select all

"This is a test<br> to see if <font color="red"><br> i can do this</font>"
if you are donig like the second situation,you probably wouldn't need to use nl2br()