可以使用 PHP 中的 substr 和 strrpos 函数来实现截取最后一个斜杠前的内容:

$url = "https://www.xxx.net/giaogiao123/article/details/121217533.html";
$lastSlash = strrpos($url, "/");
$result = substr($url, 0, $lastSlash+1);
echo $result; // 输出 https://www.xxx.net/giaogiao123/article/details/

首先,使用 strrpos 函数找到最后一个斜杠的位置,然后使用 substr 函数截取该位置之前的内容。需要注意的是,substr 函数的第三个参数是截取的长度,而不是位置,所以需要加上 1。最后将截取结果输出即可。

例如网址 httpswwwxxxnetgiaogiao123articledetails121217533html我想截取最后切割之前内容怎么用php写出就是截取结果是 httpswwwxxxnetgiaogiao123articledetails

原文地址: https://www.cveoy.top/t/topic/eDjd 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录