Last active
December 25, 2015 00:09
-
-
Save clement006/6886186 to your computer and use it in GitHub Desktop.
Get last part of a typical URL string (lowercase string separated by "-")
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
function get_last_part(string) { | |
return string.indexOf("-")<0?"":string.slice(string.lastIndexOf("-")+1); | |
} | |
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 | |
/** | |
* Get last part of a typical URL string (lowercase string separated by "-"). | |
* Example: my-blog-article-12345 => 12345 | |
* (change "-" with a dot, and you could extract a filename's extension...) | |
* @param $string | |
* @return string | |
*/ | |
function get_last_part($string) { | |
return substr(strrchr($string,'-'),1); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment