As an alternative to the substring
based answers, you could also use a regular expression, using preg_split
to split the string:
<?php
$ptn = "/\//";
$str = "http://domain.com/tag/tagname/";
$result = preg_split($ptn, $str);
$tagname = $result[count($result)-2];
echo($tagname);
?>
(The reason for the -2
is because due to the ending /
, the final element of the array will be a blank entry.)
And as an alternate to that, you could also use preg_match_all
:
<?php
$ptn = "/[a-z]+/";
$str = "http://domain.com/tag/tagname/";
preg_match_all($ptn, $str, $matches);
$tagname = $matches[count($matches)-1];
echo($tagname);
?>