I’m trying to replace the last space in a name with a
tag. Where I’ve gotten so far, the last name is simply removed “Amy L. Example” becomes “Amy L.”
Any help on this regular expression would be greatly appreciated. Just beginning to grasp how they work.
Code:
<?php $resume['name'] = preg_replace('/\s(\S*)$/', '<br />', $resume['name']); echo $resume['name'] ?>
You need to put
$1in the replacement string, so that the word you capture will be kept, not removed.