I am currently working on a PHP project where I need to convert strings using regular expressions or suitable functions. I am seeking some guidance on how to achieve this efficiently.
To provide some context, let's say I have a string like "Hello, my name is John Doe." and I want to convert it to "Hello, my name is JD.". In this example, I would like to replace the last name "Doe" with just the initials "JD".
I know that regular expressions can be quite powerful for string manipulation, but I'm not quite sure how to approach this specific task. Are there any specific regular expressions that I could use to target and replace only the last name?
Alternatively, if there is a PHP function that would make this task easier, I would greatly appreciate any suggestions or examples of how to use it.
Thank you in advance for your help!