communication
 databases
 directories
 file handling
 html and code
 image editing
 image listing
 sessions and co
 string handling
 information
 forms
 apple stuff
 image handling
 array handling
 lixlpixel
php - snippets
google search terms detected and highlighted.
remove highlighting | keep highlighting
make snippet in "html and code" - download "convert html"
 search
php - snippets

Valid CSS!

php webring logo
prev next
random list
join the Ring!

html and code - convert html was created/last modified on Mon 15 Mar 2004 6:15 AM

<?php
     
// $document should contain an HTML document.
     // This will remove HTML tags, javascript sections
     // and white space. It will also convert some
     // common HTML entities to their text equivalent.
     
     
$search = array ("'<script[^>]*?>.*?</script>'si",  // Strip out javascript
                      
"'<[\/\!]*?[^<>]*?>'si",          // Strip out HTML tags
                      
"'([\r\n])[\s]+'",                // Strip out white space
                      
"'&(quot|#34);'i",                // Replace HTML entities
                      
"'&(amp|#38);'i",
                      
"'&(lt|#60);'i",
                      
"'&(gt|#62);'i",
                      
"'&(nbsp|#160);'i",
                      
"'&(iexcl|#161);'i",
                      
"'&(cent|#162);'i",
                      
"'&(pound|#163);'i",
                      
"'&(copy|#169);'i",
                      
"'&#(\d+);'e");                    // evaluate as php
     
    //replace "xxx" with "chr(" and "yyy" with two backslashes as this site has problems otherwise
     
$replace = array ("",
                      
"",
                      
"\\1",
                      
""",
                      "
&",
                      "
<",
                      "
>",
                      " ",
                      xxx161),
                      xxx162),
                      xxx163),
                      xxx169),
                      "
xxxyyy1)");
     
     $text = preg_replace($search, $replace, $document);
     ?>

learn more about some of the PHP functions used in this snippet: array, chr, copy, eval, preg_replace

view the GNU general license - view the GNU library license - search on PHPsnippets - see your code like this

 a lixlpixel.com site

PHParadise.com - PHP-classes.org - your site on safari