html and code
|convert html
strip html and javascript from string.
full source of convert html [ line 1 - 33 ] | download convert html
| 1 | <?php |
| 2 | // $document should contain an HTML document. |
| 3 | // This will remove HTML tags, javascript sections |
| 4 | // and white space. It will also convert some |
| 5 | // common HTML entities to their text equivalent. |
| 6 | $search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript |
| 7 | "'<[/!]*?[^<>]*?>'si", // Strip out HTML tags |
| 8 | "'([rn])[s]+'", // Strip out white space |
| 9 | "'&(quot|#34);'i", // Replace HTML entities |
| 10 | "'&(amp|#38);'i", |
| 11 | "'&(lt|#60);'i", |
| 12 | "'&(gt|#62);'i", |
| 13 | "'&(nbsp|#160);'i", |
| 14 | "'&(iexcl|#161);'i", |
| 15 | "'&(cent|#162);'i", |
| 16 | "'&(pound|#163);'i", |
| 17 | "'&(copy|#169);'i", |
| 18 | "'&#(d+);'e"); // evaluate as php |
| 19 | $replace = array ("", |
| 20 | "", |
| 21 | "\1", |
| 22 | """, |
| 23 | "&", |
| 24 | "<", |
| 25 | ">", |
| 26 | " ", |
| 27 | chr(161), |
| 28 | chr(162), |
| 29 | chr(163), |
| 30 | chr(169), |
| 31 | "chr(xxx1)"); // remove the "xxx" - this is just for showing the source |
| 32 | $text = preg_replace($search, $replace, $document); |
| 33 | ?> |
27 hits by 13 users in the last 30 minutes.