Created
October 21, 2012 22:54
-
-
Save ms-studio/3928828 to your computer and use it in GitHub Desktop.
Lastname-Firstname Inversion
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
// 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 ... |
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
include( TEMPLATEPATH . '/inc/name-regex.php' ); | |
echo $regex_name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's probably better to write this as a function, like this: https://gist.github.com/ms-studio/8793349