note 42126 added to function.htmlentities
| From: | cedric at shift-zone dot be | Date: | Tue, 04 May 2004 10:02:38 +0000 |
| Subject: | note 42126 added to function.htmlentities | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69192@lists.php.net to get a copy of this message | ||
This is a conversion function for special chars.
Very usefull to convert a word document into valid html
(the html provided is successfully parsed by sablotron 0.97 using iso-8859-1 charset) :
function convertDoc2HTML($txt){
$len = strlen($txt);
$res = "";
for($i = 0; $i < $len; ++$i) {
$ord = ord($txt{$i});
// check only non-standard chars
if($ord >= 126){
$res .= "&#".$ord.";";
}
else {
// escape ", ' and \ chars
switch($ord){
case 34 :
$res .= "\\\"";
break;
case 39 :
$res .= "\'";
break;
case 92 :
$res .= "\\\\";
break;
default : // the rest does not have to be modified
$res .= $txt{$i};
}
}
}
return $res;
}
----
Manual Page -- http://www.php.net/manual/en/function.htmlentities.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42126
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42126&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42126&report=yes
Search -- http://master.php.net/manage/user-notes.php