开发者

Retrieve custom URL segment with CI

开发者 https://www.devze.com 2023-04-02 03:46 出处:网络
I looked at the URL helper and URI class and I noticed that both of these work off the URL in the address bar. Is there a way I can use this helper or class with my own URL string? I wan开发者_开发知识

I looked at the URL helper and URI class and I noticed that both of these work off the URL in the address bar. Is there a way I can use this helper or class with my own URL string? I wan开发者_开发知识库t to retrieve the last segment of a URL I give and I don't want to resort to preg_match unless I need to. Is there a way to do this with codeigniter functionality?


If you have a string in the format of http://example.com/foo/bar (I presume that's what you mean by 'own URL string'?), you should be able to just do something like this:

$url = "http://example.com/foo/bar";
$parts = explode("/", $url);
$last = end($parts);  // => bar


You can use:

$this->uri->segment($this->uri->total_segments())

or

array_pop($this->uri->segment_array())

if you want to use CI functionality.

0

精彩评论

暂无评论...
验证码 换一张
取 消