我想获得这个URL的最后一个单词:
http://localhost:8888/articles/tags/Europa
我如何在Laravel中制作这个?有了这个{{URL::current()}}
,我得到了完整的URL。我已经尝试过{{URL::current().split('/').last}}
,但后来我得到错误:Function split() is deprecated
也可以使用Request类的segment方法。
$var = Request::segment(3);
这将根据API文档捕获URI的第三段:http://laravel.com/api/5.1/Illuminate/Http/Request.html method_segment
尝试使用preg_split()
代替
的例子:
$var = 'http://localhost:8888/articles/tags/Europa';
$var = preg_split("/'//", 'http://localhost:8888/articles/tags/Europa');
array_pop($var ); //removes last
我不能删除这个,因为它是公认的答案,但请参阅josh088的答案