I have i string in my PHP-code which looks like this
Bokad av Anna Göransson 14:45 - 15:45
Now i want to replace "Anna" with "A.". How can i do that using regexp and PHP?
I have i string in my PHP-code which looks like this
Bokad av Anna Göransson 14:45 - 15:45
Now i want to replace "Anna" with "A.". How can i do that using regexp and PHP?
You can use something different if the string is dynamic and subject to change.
$string = "okad av Anna Göransson 14:45 - 15:45";
$names = explode(" ",$string);
$names[2] = strtoupper($names[2][0]).".";
$string = implode(" ",$names);
strtoupper(substr($names[2],0,1))."."; can also be written as strtoupper($names[2][0]).".";Anna) being the 3rd word (array index 2). In my limited experience, there are always cases where this won't be true.