php 路径获得最后一个参数
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 路径获得最后一个参数相关的知识,希望对你有一定的参考价值。
<span style="color: #000000; font-weight: bold;">function</span> path_get_last_arg<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$path</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span>
<span style="color: #0000ff;">$path</span> = <a href="http://www.php.net/str_replace"><span style="color: #000066;">str_replace</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\\</span>'</span>, <span style="color: #ff0000;">'/'</span>, <span style="color: #0000ff;">$path</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$path</span> = <a href="http://www.php.net/preg_replace"><span style="color: #000066;">preg_replace</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'/<span style="color: #000099; font-weight: bold;">\/</span>+$/'</span>, <span style="color: #ff0000;">''</span>, <span style="color: #0000ff;">$path</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$path</span> = <a href="http://www.php.net/explode"><span style="color: #000066;">explode</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'/'</span>, <span style="color: #0000ff;">$path</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$l</span> = <a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$path</span><span style="color: #66cc66;">)</span><span style="color: #cc66cc;">-1</span>;
<span style="color: #b1b100;">return</span> <a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$path</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$l</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">)</span> ? <span style="color: #0000ff;">$path</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$l</span><span style="color: #66cc66;">]</span> : <span style="color: #ff0000;">''</span>;
<span style="color: #66cc66;">}</span>
以上是关于php 路径获得最后一个参数的主要内容,如果未能解决你的问题,请参考以下文章