Current location: Hot Scripts Forums » Programming Languages » PHP » Strip HTML


Strip HTML

Reply
  #1 (permalink)  
Old 10-24-07, 09:47 AM
blinn_shade's Avatar
blinn_shade blinn_shade is offline
Aspiring Coder
 
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
Strip HTML

Hey,

I have used htmlentities() to insert HTML in the database. This outputs the HTML as : <p> etc...



Now I need to strip these values so it doesn't show any HTML or any HTML code. I know tat using : html_entity_decode(); restores the HTML to displayable HTML. But i need to get rid of everything to do with HTML. I just need the text in the html to be returned.

Can someone help me please?

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 10-24-07, 09:51 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
www.php.net/strip_tags

This might be what you're looking for.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 10-24-07, 10:18 AM
blinn_shade's Avatar
blinn_shade blinn_shade is offline
Aspiring Coder
 
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
No it's not. I am looking for a way to remove all the entities of HTML as such: &amp;lt;p&amp;gt; which would be <p>. Strip tags only removes real html strings such as:

HTML Code:
<p>Text here</p>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 10-24-07, 10:26 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Use html_entity_decode() first, and then strip_tags() ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 10-24-07, 11:33 AM
blinn_shade's Avatar
blinn_shade blinn_shade is offline
Aspiring Coder
 
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
I've tried that before I posted here. it seems to return the text and HTML but with making the HTML display as text.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 10-24-07, 11:46 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
You must be doing something wrong somewhere, because the method I mentioned above does work.

You have the text in your database like this:
Code:
&lt;p&gt;Text here&lt;/p&gt;
Now to convert it into the wanted format you just do:
PHP Code:

$text strip_tags(html_entity_decode($text)); 

And this outputs: "Texet here".

If that's not your case, post your actual code to spot the error.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 10-24-07, 02:27 PM
blinn_shade's Avatar
blinn_shade blinn_shade is offline
Aspiring Coder
 
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
As I said I have trid that. It removed the first: &lt;p&gt; but doesn't remove any more then one. Is there another way to this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 10-24-07, 02:34 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
This is probably the best way of doing it, and it does work. So why not post your code so we can try to find out why it's not working for you?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 10-24-07, 05:30 PM
blinn_shade's Avatar
blinn_shade blinn_shade is offline
Aspiring Coder
 
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
My code is over a thousand lines ;(
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 10-24-07, 05:37 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Well how about the part that has to do with this? From where it fetches the data from the database, to the part where it's being displayed?

There might be another way to achieve the same, but would be more complicated since you want to strip the HTML as well. And there must be just a small error somewhere.

As you describe, it "displays the HTML as text", I guess you're not applying the function to the right variable or something along these lines.

But at the moment I can't do more than guess.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
html tutoral thefrtman HTML/XHTML/XML 5 04-27-09 11:25 AM
HTML Form 1 -> Perl -> return response to HTML form 2 Oleks Perl 13 10-18-06 05:59 PM
java codes to strip html tags y2j150 JavaScript 1 08-05-05 04:44 PM
Need website design or HTML coding help? website_help HTML/XHTML/XML 0 05-26-05 01:07 PM
freeware code to strip HTML tags ? xgab Perl 5 04-19-04 08:31 PM


All times are GMT -5. The time now is 07:30 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.