I would like to turn uppercase h1, h2,... tags into capitalized text with PHP. I'm close, but not there yet. The below snippet does not turn the first character of "LOREM" into uppercase (probably because it tries to uppercase '<'). It would be easy to modify the callback PHP function, but I wish I could do this by only modifying the regex piece:
$var = "
<h1>LOREM IPSUM DOLORES AMET</h1>
THIS IS SOME TEXT
<H2>LOREM IPSUM DOLORES AMET</H2>";
$line = preg_replace_callback(
'/<h[1-9]>(.*)\>/i',
function ($matches) {
return ucfirst(strtolower($matches[0]));
},
$var
);
print($line);
Results in:
<h1>lorem ipsum dolores amet</h1>
THIS IS SOME TEXT
<H2>lorem ipsum dolores amet</H2>
Desired output:
<h1>Lorem ipsum dolores amet</h1>
THIS IS SOME TEXT
<H2>Lorem ipsum dolores amet</H2>