I found this script hxxp://nadeausoftware.com/articles/2007/09/php_tip_how_strip_html_tags_web_page that should strip HTML tags, scripts, and styles from a web page but it doesn't.
What is the problem?
How to strip HTML tags, scripts, and styles from a web page
Started by sergo, Oct 26 2009 09:28 AM
10 replies to this topic
#1
Posted 26 October 2009 - 09:28 AM
|
|
|
#2
Posted 26 October 2009 - 10:26 AM
I suggest you to use the strip_tags() function from the php library. That's the easiest way. Bye!

#3
Posted 26 October 2009 - 10:37 AM
strip_tags() function is useless
#4
Posted 26 October 2009 - 12:21 PM
#5
Guest_Jordan_*
Posted 26 October 2009 - 03:08 PM
Guest_Jordan_*
Why do you say the strip_tags function is useless? It will do exactly what you stated that you need above.
#6
Posted 27 October 2009 - 02:11 AM
I have tried it and it doesn't work, it returns the tags, not the text without tags
#7
Posted 27 October 2009 - 02:32 AM
sergo said:
I have tried it and it doesn't work, it returns the tags, not the text without tags
<?php $text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>'; echo strip_tags($text); echo "\n"; // Allow <p> and <a> echo strip_tags($text, '<p><a>'); ?>

#8
Posted 27 October 2009 - 03:02 AM
sergo said:
I have tried it and it doesn't work, it returns the tags, not the text without tags
It works just fine. :confused: Post your code. You are probably using it wrong. Either that or you don't understand the function correctly. It is working but you think it isn't.
#9
Posted 27 October 2009 - 03:42 AM
How do I use this to remove something like this ("something"); or Blaf Blab ?
<?php $text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>'; echo strip_tags($text); echo "\n"; // Allow <p> and <a> echo strip_tags($text, '<p><a>'); ?>
#10
Posted 27 October 2009 - 03:51 AM
sergo said:
How do I use this to remove something like this ("something"); or Blaf Blab ?
<?php $text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>'; echo strip_tags($text); echo "\n"; // Allow <p> and <a> echo strip_tags($text, '<p><a>'); ?>
$string = str_replace("something", "", $string);

#11
Guest_Jordan_*
Posted 27 October 2009 - 04:29 AM
Guest_Jordan_*
Try this, I found it on the PHP manual via user submitted comments:
<?php
function html2txt($document){
$search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA
);
$text = preg_replace($search, '', $document);
return $text;
}
?>


Sign In
Create Account

Back to top










