我想得到这个网址的最后一句话:
http://localhost:8888/articles/tags/Europa
我怎么能在Laravel中做到这一点?使用此{{URL::current()}}
我正在获取完整的网址。我尝试了{{URL::current().split('/').last}}
,但后来收到错误:Function split() is deprecated
答案 0 :(得分:5)
您还可以使用Request类的segment方法。
$var = Request::segment(3);
这将根据API文档捕获URI的第3段: http://laravel.com/api/5.1/Illuminate/Http/Request.html#method_segment
答案 1 :(得分:1)
尝试使用preg_split()
代替
示例:
$var = 'http://localhost:8888/articles/tags/Europa';
$var = preg_split("/\//", 'http://localhost:8888/articles/tags/Europa');
array_pop($var ); //removes last
<强>更新强>
我无法删除此内容,因为这是已接受的答案,但请参阅josh088's answer