Date: 07/25/00
- Next message: Kristian Köhntopp: "[PHP-DOC] cvs: phpdoc /en/functions curl.xml"
- Previous message: Monte Ohrt: "[PHP-DOC] cvs: phpdoc /en/functions pcre.xml"
- Next in thread: Monte Ohrt: "[PHP-DOC] cvs: phpdoc /en/functions pcre.xml"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
mohrt Tue Jul 25 12:25:10 2000 EDT
Modified files:
/phpdoc/en/functions pcre.xml
Log:
added example to preg_replace()
Index: phpdoc/en/functions/pcre.xml
diff -u phpdoc/en/functions/pcre.xml:1.14 phpdoc/en/functions/pcre.xml:1.15
--- phpdoc/en/functions/pcre.xml:1.14 Tue Jul 25 12:13:40 2000
+++ phpdoc/en/functions/pcre.xml Tue Jul 25 12:25:10 2000
@@ -357,6 +357,45 @@
This would capitalize all HTML tags in the input text.
</para>
</example>
+ <example>
+ <title>Convert HTML to text</title>
+ <programlisting>
+
+ // $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
+ "'&(quote|#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"
+ );
+
+ $replace = array( "",
+ "",
+ "\\1",
+ "\"",
+ "&",
+ "&lt;",
+ "&gt;",
+ " ",
+ chr(161),
+ chr(162),
+ chr(163),
+ chr(169));
+
+ $text = preg_replace($search,$replace,$document);
+ </programlisting>
+ </example>
</para>
<para>
See also <function>preg_match</function>,
- Next message: Kristian Köhntopp: "[PHP-DOC] cvs: phpdoc /en/functions curl.xml"
- Previous message: Monte Ohrt: "[PHP-DOC] cvs: phpdoc /en/functions pcre.xml"
- Next in thread: Monte Ohrt: "[PHP-DOC] cvs: phpdoc /en/functions pcre.xml"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

