note 8590 deleted from function.preg-replace by jimw
| From: | jimw@php.net | Date: | Thu, 20 Dec 2001 23:27:14 +0000 |
| Subject: | note 8590 deleted from function.preg-replace by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-23562@lists.php.net to get a copy of this message | ||
[Editor's note: Simpler solution, use get_html_tranlastion_table(), see examples in that manual
entry]
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 ""e" should
be """. 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