Skip to content

Instantly share code, notes, and snippets.

@duskohu
Created October 16, 2013 12:05
Show Gist options
  • Save duskohu/7006660 to your computer and use it in GitHub Desktop.
Save duskohu/7006660 to your computer and use it in GitHub Desktop.
Parse degree before, name, surname and degree after from string.
<?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