You are here: Re: URLs « PHP Programming Language « IT news, forums, messages
Re: URLs

Posted by Joe Estock on 12/18/60 11:50

Joe Estock wrote:
> 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;
> }
> }

Whoops, misread your intent. Corrections follow (again, untested).

$flag = false;
$j = 0;
for ($i = strlen($url); $i > 0; $i--)
{
if ($url{$i} == '/')
{
if ($flag == true)
{
/* we have our match */
$url = substr($url, $i, ($j - $i));
break;
}

/* got the first / */
$flag = true;
$j = $i;
}
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация