Skip to content

Instantly share code, notes, and snippets.

@ms-studio
Created October 21, 2012 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ms-studio/3928828 to your computer and use it in GitHub Desktop.
Save ms-studio/3928828 to your computer and use it in GitHub Desktop.
Lastname-Firstname Inversion
// a little snippet instead of the_title()
$mystring = get_the_title();
$findme = ',';
$pos = strpos($mystring, $findme);
if ($pos === false) {
$regex_name = $mystring;
} else {
$firstname = strstr($mystring, ',');
$lastname = strstr($mystring, ',', true); // As of PHP 5.3.0
$firstname = trim( substr($firstname, 1) );
$regex_name = $firstname." ".$lastname;
}
// now we can echo $regex_name ...
include( TEMPLATEPATH . '/inc/name-regex.php' );
echo $regex_name;
@ms-studio
Copy link
Author

It's probably better to write this as a function, like this: https://gist.github.com/ms-studio/8793349

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment