note 8590 added to preg_replace
| From: | gherson at php2 dot chek dot com | Date: | Wed, 20 Sep 2000 08:32:20 +0000 |
| Subject: | note 8590 added to preg_replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-5210@lists.php.net to get a copy of this message | ||
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
http://www.php.net/manual/function.preg-replace.php