[PHP-DOC] cvs: phpdoc /en/functions pcre.xml From: Monte Ohrt (monte <email protected>)
Date: 07/25/00

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("'&lt;script[^&gt;]*?&gt;.*?&lt;/script&gt;'si", // strip out javascript
+ "'&lt;[\/\!]*?[^&lt;&gt;]*?&gt;'si", // strip out html tags
+ "'([\r\n])[\s]+'", // strip out white space
+ "'&amp;(quote|#34);'i", // replace html entities
+ "'&amp;(amp|#38);'i",
+ "'&amp;(lt|#60);'i",
+ "'&amp;(gt|#62);'i",
+ "'&amp;(nbsp|#160);'i",
+ "'&amp;(iexcl|#161);'i",
+ "'&amp;(cent|#162);'i",
+ "'&amp;(pound|#163);'i",
+ "'&amp;(copy|#169);'i"
+ );
+
+ $replace = array( "",
+ "",
+ "\\1",
+ "\"",
+ "&amp;",
+ "&amp;lt;",
+ "&amp;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>,