I've tried using the below
$string= 'hello world<br>this is newline<br><br>another line';
echo $string.'<hr><br>';
echo preg_replace_callback('/^[a-zA-Z0-9]/m', function($m) {
return strtoupper($m[0]);
}, $string);
the output:
Hello world
this is newline
another line
i need to change the first letter of word "this" and "another" too. so the output become like this:
Hello world
This is newline
Another line
Thanks.
` is not a new line in anything except a browser/application that is rendering HTML. You could try `/(^|
)` or convert them to new lines. Also a `.` would probably be easier than a character class unless you only want to capitalize `a-z` (if that is case character class can be trimmed down to `[a-z]`). – chris85 Mar 03 '17 at 02:26