How can I make the content in a string to upper case but not the html entities in it? Is it possible?
$str = 'FUNDA MENTALISM';
echo strtoupper($str);
I want to produce this,
'FUNDA MENTALISM'
but I get this with strtoupper()
'FUNDA MENTALISM'
I know you haven't listed CSS in your tags, but most of the time it is easier to leave this to the client side (if you only intended this string for browser display).
Applying CSS text-transform: uppercase;
will do this for you.
Well, remove the entities and use a multi-byte character set!
$string = html_entity_decode($string, ENT_COMPAT, 'UTF-8');
$string = mb_convert_case($string, MB_CASE_UPPER, 'UTF-8');
Then output the string. There's no need for most html entities, just use the native characters and set the output of the document properly.
If you really must use the entities, a regex is in order:
$callback = function($match) {
return strtoupper($match[1]);
}
$regex = '/(\w+(?=&)|(?<=;)\w+)/';
$string = preg_replace_callback($regex, $callback, $string);
Note that I haven't tested that regex, but it should work since it's looking for letters that are not immediately followed by a ;
character...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With