print text without html

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
keveh
Forum Commoner
Posts: 27
Joined: Mon Aug 08, 2005 5:50 am

print text without html

Post 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]
Last edited by keveh on Thu Sep 28, 2006 3:35 pm, edited 1 time in total.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

maybe soemthing like

Code: Select all

strip_tags(' $string',<br>);
keveh
Forum Commoner
Posts: 27
Joined: Mon Aug 08, 2005 5:50 am

Post by keveh »

Thanks, I did it by using the following:

Code: Select all

nl2br(strip_tags($comments[comText], '<br>'))
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post 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()
Post Reply