PHP 文本操作,取文本问题

WBOY
Release: 2016-06-23 14:11:01
Original
1100 people have browsed it

域名:http://localhost/down.php?add=down/0522/img.png (域名为随机)


$img = $add

echo $img;
?>
===================================================================

$img 只取图片的名称(img.png)

也就是说删除 (http://localhost/down?add=down/0522/)只取 (img.png)


什么写?求大神。


回复讨论(解决方案)

$img = basename($_GET['add']);

$img = basename($_GET['add']);


谢谢,能说说原理吗?新手求解、、、

url 参数通过 $_GET 数组获取,这是 php 的约定
basename 函数用于取得文件名(即去掉路径)

url 参数通过 $_GET 数组获取,这是 php 的约定
basename 函数用于取得文件名(即去掉路径)


万分感谢

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template