[wd_asp elements=’search’ ratio=’100%’ id=1]

Get character count of a string saved in database – html_entity_decode not working

23rd September 2022

Php - Strings

php codehaven

As you can see the saved string has html code within, and when the html_entity_decode is performed upon the string this is being included within the character count.

With a slight adjustment to the code by adding – ENT_QUOTES,”UTF-8″ we get the correct amount of characters within the string as seem by a webpage after decode.

echo $string1 = html_entity_decode("We're the smartest SEO Agency. We love SEO, so let's grab a coffee & find out how we can make you shine in search with our SEO!");
echo "
";

echo strlen($string1);

echo "
";

echo $string2 = html_entity_decode("We're the smartest SEO Agency. We love SEO, so let's grab a coffee & find out how we can make you shine in search with our SEO!",ENT_QUOTES,"UTF-8");
echo "
";

echo strlen($string2);

charactercount