Some users like to write post title all in uppercase, which is completely annoying. Instead of asking them to write it again I want to know what percentage of the title they wrote is uppercase so that if they exceed 50% I just apply strtolower.
My idea is to turn their string to lowercase and see how different it is from the original string (3 different characters would mean originally there were 3 uppercase characters):
$title = 'AAAA';
$title2 = strtolower($title);
How do I compare $title with $title2 to get the number of characters that don’t match?
Eg:
$title = 'AAAa'
$title2 = 'aaaa'
$differences = '3';
1 Answer