Created
October 16, 2013 12:05
-
-
Save duskohu/7006660 to your computer and use it in GitHub Desktop.
Parse degree before, name, surname and degree after from string.
This file contains 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
<?php | |
$list = array( | |
'Ing. Peter Jablčko', | |
'Ondrej koláč', | |
'Miro Hámor PhD.', | |
'Ing. Palo Kámor PhD.', | |
'Ing. Dr. Palo Kamor PhD.', | |
'Ing. Dr. Palo Kamor PhD. xxx. ' | |
); | |
foreach ($list as $name) { | |
$pattern = '/^(?P<degreeBefore>.+[.]\s*)?\s*(?P<name>[^.\s]+)\s+(?P<surname>[^.\s]+)\s*(?P<degreeAfter>.+[.]\s*)?$/'; | |
preg_match($pattern, trim($name), $results); | |
var_dump($results); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment