Posted by Joe Estock on 12/18/50 11:50
J Huntley Palmer wrote:
> How may I capture the last /.../ in a url?
>
> eg.. www.foo.com/foo/bar/baz/index.php?param=1
>
> I want to capture 'baz'.
>
> Thanks
Start from the end of the string and work backwards until you hit the
second /. Untested code follows:
$flag = false;
for ($i = strlen($url); $i > 0; $i--)
{
if ($url{$i} == '/')
{
if ($flag == true)
{
/* we have our match */
$url = substr($url, $i);
break;
}
/* got the first / */
$flag = true;
}
}
[Back to original message]
|