Re: note 8590 added to preg_replace

From: Date: Tue, 19 Sep 2000 23:09:09 +0000
Subject: Re: note 8590 added to preg_replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-5226@lists.php.net to get a copy of this message
See examples in get_html_translation_table() for a simpler solution. I added this comment to your note. --- gherson@php2.chek.com, at <snet.net@php2.chek.com> wrote: > Didn't like how Example 3 worked for me: it > substituted in text in the wrong places, removed > carriage returns so lines ran together, and worst of > all :) it's "&quote" should be "&quot". This was > closer: > > if ($argv[1]=="-f") { //Filename(s) passed in. > foreach ($argv as $file) { > if ($file=="-f") continue; > $file_text = > strip_tags(join('',file($file))); > htmlchars2txt($file_text); > } > } else { //Text passed in. > htmlchars2txt($argv[1]); > } > > function htmlchars2txt($text) { > $text = ereg_replace("&(quot|#34);","\"",$text); > $text = ereg_replace("&(amp|#38);","&",$text); > $text = ereg_replace("&(lt|#60);","<",$text); > $text = ereg_replace("&(gt|#62);",">",$text); > $text = ereg_replace("&(nbsp|#160);"," ",$text); > $text = > ereg_replace("&(iexcl|#161);",161,$text); > $text = ereg_replace("&(cent|#162);",162,$text); > $text = > ereg_replace("&(pound|#163);",163,$text); > $text = ereg_replace("&(copy|#169);",169,$text); > $text = > ereg_replace("?([0-9]{1,3});","\\1",$text); > //$text = > preg_replace("/?([0-9]{1,3});/e","chr('\\1')",$text); > Same as above line. > echo $text; > } > > // Example, from command line: > // stripper.php -f /tmp/egascii.htm > /tmp/tmpdata_.htm > > http://www.php.net/manual/function.preg-replace.php > > > > -- > PHP Notes Mailing List (http://www.php.net/) > To unsubscribe, e-mail: > php-notes-unsubscribe@lists.php.net > For additional commands, e-mail: > php-notes-help@lists.php.net > To contact the list administrators, e-mail: > php-list-admin@lists.php.net > ===== --- Jesus M. Castagnetto (jcastagnetto@yahoo.com) __________________________________________________ Do You Yahoo!? Send instant messages & get email alerts with Yahoo! Messenger. http://im.yahoo.com/

« previous php.notes (#5226) next »