note 42126 modified in function.htmlentities by danbrown

From: Date: Sun, 17 May 2009 17:06:29 +0000
Subject: note 42126 modified in function.htmlentities by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154940@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) : <?php 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; } ?> --was-- 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; } http://php.net/manual/en/function.htmlentities.php

« previous php.notes (#154940) next »