I want to count how many characters a certain string has in PHP, but I cant get it to work.
I did a var_dump and this is what I got:
string(23) "Children’s Center"
It seems like '
gets translated to ’s
This makes it impossible to get the actual character count. I tried using html_entity_decode
but it did not help.
Anyone?
EDIT: My function looks like this now:
function make_shorter($string, $maxlength)
{
$string = stripslashes($string);
$string = html_entity_decode($string);
if ( mb_strlen(utf8_decode($string)) > $maxlength)
return substr($string,0,$maxlength).'...';
else
return $string;
}
I can't change how the data gets in to the system. I can only modify it's output.
(It's a wordpress site)