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.
精彩评论