- substr_replace: documentation ( source)
- strrpos: documentation ( source)
<?php
$url = "http://www.foo.com/parentfoo/childfoo/";
$last = strrpos($url, '/');
if ($last === false) {
return false;
}
$next_to_last = strrpos($url, '/', $last - strlen($url) - 1);
echo $var1 = substr_replace($url,"",$last);
$var2 = substr_replace($var1,"#",$next_to_last);