Skip to content

Instantly share code, notes, and snippets.

@clement006
Last active December 25, 2015 00:09
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 clement006/6886186 to your computer and use it in GitHub Desktop.
Save clement006/6886186 to your computer and use it in GitHub Desktop.
Get last part of a typical URL string (lowercase string separated by "-")
function get_last_part(string) {
return string.indexOf("-")<0?"":string.slice(string.lastIndexOf("-")+1);
}
<?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