phpreplacecapitalizeucfirst

Capitalize first letter in <em>


$item = 'some <html> goes <div class="here"> and </div> can be placed <em>     some words</em>, and then more </html> can exist';

How do I capitalize the first letter of the first word inside <em>...</em> only?


Solution

  • this?

    function ucfirstword($str) {
       $estr = explode(" ",$str);
       $estr[0] = ucfirst($estr[0]);
       return implode(" ",$estr);
    }
    
    ...
    echo "<em>     ".ucfirstword("some words")."</em>";