Last active
November 19, 2018 17:45
-
-
Save interactiveRob/eb69c4ca49a20f9e2d45abc0826febe2 to your computer and use it in GitHub Desktop.
Regex Replace to break any name into two lines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Two step Regex replace to make sure names always break into 2 lines: | |
| 1) Remove all spaces entered by Human error from the end of the Full Name | |
| 2) Replace spaces with <br/> tags. Definitions | |
| (?!^\s) Don't match spaces that come at the beginning of the name | |
| (?!\w+\s) Also don't match a space after the First Name if there is another | |
| word followed by a space after that. This prevents breaking the line for Middle Names. | |
| */ | |
| $title = preg_replace('/\s+$/', '', $title); | |
| $title = preg_replace('/(?!^\s)\s(?!\w+\s)/', '<br/>', $title); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment