senyo Posted October 26, 2009 Share Posted October 26, 2009 I found this script http://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? Quote Link to comment https://forums.phpfreaks.com/topic/179077-how-to-strip-html-tags-scripts-and-styles-from-a-web-page/ Share on other sites More sharing options...
senyo Posted October 26, 2009 Author Share Posted October 26, 2009 I use PHP 5 Quote Link to comment https://forums.phpfreaks.com/topic/179077-how-to-strip-html-tags-scripts-and-styles-from-a-web-page/#findComment-944812 Share on other sites More sharing options...
JonnoTheDev Posted October 26, 2009 Share Posted October 26, 2009 Read on the function http://uk3.php.net/strip_tags Quote Link to comment https://forums.phpfreaks.com/topic/179077-how-to-strip-html-tags-scripts-and-styles-from-a-web-page/#findComment-944813 Share on other sites More sharing options...
senyo Posted October 26, 2009 Author Share Posted October 26, 2009 How to use it? Quote Link to comment https://forums.phpfreaks.com/topic/179077-how-to-strip-html-tags-scripts-and-styles-from-a-web-page/#findComment-944830 Share on other sites More sharing options...
senyo Posted October 26, 2009 Author Share Posted October 26, 2009 I tried all the every script but they don't work together Quote Link to comment https://forums.phpfreaks.com/topic/179077-how-to-strip-html-tags-scripts-and-styles-from-a-web-page/#findComment-944847 Share on other sites More sharing options...
senyo Posted October 26, 2009 Author Share Posted October 26, 2009 I don't think that this script work, maybe it worked but now it is useless Quote Link to comment https://forums.phpfreaks.com/topic/179077-how-to-strip-html-tags-scripts-and-styles-from-a-web-page/#findComment-944884 Share on other sites More sharing options...
JAY6390 Posted October 26, 2009 Share Posted October 26, 2009 $output = strip_tags($input_text); Quote Link to comment https://forums.phpfreaks.com/topic/179077-how-to-strip-html-tags-scripts-and-styles-from-a-web-page/#findComment-944885 Share on other sites More sharing options...
senyo Posted October 26, 2009 Author Share Posted October 26, 2009 $output = strip_tags($input_text); What is the purpose of this? Quote Link to comment https://forums.phpfreaks.com/topic/179077-how-to-strip-html-tags-scripts-and-styles-from-a-web-page/#findComment-944894 Share on other sites More sharing options...
mikesta707 Posted October 26, 2009 Share Posted October 26, 2009 ... it strips php tags from the strings, which seems pretty obvious given its name. Before you try to use someone else's code, I suggest you learn PHP basics, or at least so you can actually make it work. it seems you don't even know how functions work Quote Link to comment https://forums.phpfreaks.com/topic/179077-how-to-strip-html-tags-scripts-and-styles-from-a-web-page/#findComment-944896 Share on other sites More sharing options...
senyo Posted October 26, 2009 Author Share Posted October 26, 2009 I know what it is the name but it doesn't actually work any this is not important My question is why this script doesn't work? <?php /** * Strip out (X)HTML tags and invisible content. This function * is useful as a prelude to tokenizing the visible text of a page * for use in a search engine or spam detector/remover. * * Unlike PHP's built-in strip_tags() function, this function will * remove invisible parts of a web page that normally should not be * indexed or passed through a spam filter. This includes style * blocks, scripts, applets, embedded objects, and everything in the * page header. * * In anticipation of tokenizing the visible text, this function * detects (X)HTML block tags (such as divs, paragraphs, and table * cells) and inserts a carriage return before each one. This * insures that after tags are removed, words before and after the * tag are not erroneously joined into a single word. * * Parameters: * text the (X)HTML text to strip * * Return values: * the stripped text * * See: * http://nadeausoftware.com/articles/2007/09/php_tip_how_strip_html_tags_web_page */ function strip_html_tags( $text ) { // PHP's strip_tags() function will remove tags, but it // doesn't remove scripts, styles, and other unwanted // invisible text between tags. Also, as a prelude to // tokenizing the text, we need to insure that when // block-level tags (such as <p> or <div>) are removed, // neighboring words aren't joined. $text = preg_replace( array( // Remove invisible content '@<head[^>]*?>.*?</head>@siu', '@<style[^>]*?>.*?</style>@siu', '@<script[^>]*?.*?</script>@siu', '@<object[^>]*?.*?</object>@siu', '@<embed[^>]*?.*?</embed>@siu', '@<applet[^>]*?.*?</applet>@siu', '@<noframes[^>]*?.*?</noframes>@siu', '@<noscript[^>]*?.*?</noscript>@siu', '@<noembed[^>]*?.*?</noembed>@siu', // Add line breaks before & after blocks '@<((br)|(hr))@iu', '@</?((address)|(blockquote)|(center)|(del))@iu', '@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu', '@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu', '@</?((table)|(th)|(td)|(caption))@iu', '@</?((form)|(button)|(fieldset)|(legend)|(input))@iu', '@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu', '@</?((frameset)|(frame)|(iframe))@iu', ), array( ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", ), $text ); // Remove all remaining tags and comments and return. return strip_tags( $text ); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/179077-how-to-strip-html-tags-scripts-and-styles-from-a-web-page/#findComment-944907 Share on other sites More sharing options...
JAY6390 Posted October 26, 2009 Share Posted October 26, 2009 This line @<head[^>]*?>.*?</head>@siu', should be '@<head[^>]*?>.*?</head>@siu', Note the missing apostrophe at the beginning of the first Quote Link to comment https://forums.phpfreaks.com/topic/179077-how-to-strip-html-tags-scripts-and-styles-from-a-web-page/#findComment-944909 Share on other sites More sharing options...
senyo Posted October 26, 2009 Author Share Posted October 26, 2009 that is not the problem, the script has the apostrophe, the forum doesn't shows it Quote Link to comment https://forums.phpfreaks.com/topic/179077-how-to-strip-html-tags-scripts-and-styles-from-a-web-page/#findComment-944914 Share on other sites More sharing options...
mikesta707 Posted October 26, 2009 Share Posted October 26, 2009 please put your code in code tags. How are you using the function? can you show an example of where you use it in your code. that function seems perfectly fine... Quote Link to comment https://forums.phpfreaks.com/topic/179077-how-to-strip-html-tags-scripts-and-styles-from-a-web-page/#findComment-944917 Share on other sites More sharing options...
JAY6390 Posted October 26, 2009 Share Posted October 26, 2009 I see. That script is a FUNCTION ONLY and as such it doesn't execute. It is meant to be used with your own code where you call the function. There is nothing wrong with it Quote Link to comment https://forums.phpfreaks.com/topic/179077-how-to-strip-html-tags-scripts-and-styles-from-a-web-page/#findComment-944918 Share on other sites More sharing options...
senyo Posted October 26, 2009 Author Share Posted October 26, 2009 so this script only shows the striped tags? Quote Link to comment https://forums.phpfreaks.com/topic/179077-how-to-strip-html-tags-scripts-and-styles-from-a-web-page/#findComment-944923 Share on other sites More sharing options...
mikesta707 Posted October 26, 2009 Share Posted October 26, 2009 .. do you know what a function is? if you don't; learn PHP before you try to just copy paste code and put it on your website. debugging your code will be much less of a headache Quote Link to comment https://forums.phpfreaks.com/topic/179077-how-to-strip-html-tags-scripts-and-styles-from-a-web-page/#findComment-944933 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.