note 53129 modified in function.strstr by danbrown
| From: | danbrown@php.net | Date: | Fri, 28 Nov 2008 20:05:23 +0000 |
| Subject: | note 53129 modified in function.strstr by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147175@lists.php.net to get a copy of this message | ||
When encoding ASCII strings to HTML size-limited strings, sometimes some HTML special chars were
cut.
For example, when encoding "��" to a string of size 10, you would get:
"Ã &a" => the second character is cut.
This function will remove any unterminated HTML special characters from the string...
<?php
function cut_html($string)
{
$a=$string;
while ($a = strstr($a, '&'))
{
echo "'".$a."'\n";
$b=strstr($a, ';');
if (!$b)
{
echo "couper...\n";
$nb=strlen($a);
return substr($string, 0, strlen($string)-$nb);
}
$a=substr($a,1,strlen($a)-1);
}
return $string;
}
?>
--was--
When encoding ASCII strings to HTML size-limited strings, sometimes some HTML special chars were
cut.
For example, when encoding "àà" to a string of size 10, you would get:
"à&a" => the second character is cut.
This function will remove any unterminated HTML special characters from the string...
function cut_html($string)
{
$a=$string;
while ($a = strstr($a, '&'))
{
echo "'".$a."'\n";
$b=strstr($a, ';');
if (!$b)
{
echo "couper...\n";
$nb=strlen($a);
return substr($string, 0, strlen($string)-$nb);
}
$a=substr($a,1,strlen($a)-1);
}
return $string;
}
http://php.net/manual/en/function.strstr.php