Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Class 使用CI检索自定义URL段_Class_Url_Codeigniter_Helper - Fatal编程技术网

Class 使用CI检索自定义URL段

Class 使用CI检索自定义URL段,class,url,codeigniter,helper,Class,Url,Codeigniter,Helper,我查看了URL帮助器和URI类,发现这两个类都与地址栏中的URL无关。有没有一种方法可以将这个助手或类与我自己的URL字符串一起使用?我想检索我给出的URL的最后一段,我不想求助于preg\u match,除非我需要。有没有办法使用codeigniter功能实现这一点?如果您的字符串格式为http://example.com/foo/bar(我想这就是你所说的“自己的URL字符串”的意思吧?),你应该可以这样做: $url = "http://example.com/foo/bar"; $par

我查看了URL帮助器和URI类,发现这两个类都与地址栏中的URL无关。有没有一种方法可以将这个助手或类与我自己的URL字符串一起使用?我想检索我给出的URL的最后一段,我不想求助于
preg\u match
,除非我需要。有没有办法使用codeigniter功能实现这一点?

如果您的字符串格式为http://example.com/foo/bar(我想这就是你所说的“自己的URL字符串”的意思吧?),你应该可以这样做:

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

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

如果要使用CI功能

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