我遇到了一个麻烦,我怎么能从网址中提取文件夹名称
示例 - http://localhost/posts/author/FOLDER_NAME/live/?red=home
我想回复FOLDER_NAME到我的网页
<?php echo $name; ?>
答案 0 :(得分:1)
您可以按“/”分解字符串并获取正确的元素:
print explode("/", "http://localhost/posts/author/FOLDER_NAME/live/?red=home")[5];
答案 1 :(得分:1)
有几种方法可以满足您的需求,一种简单的方法就是使用preg_replace:
$url = "http://localhost/posts/author/FOLDER_NAME/live/?red=home"
$folder = preg_replace('%.*author/(.*?)/live.*%', '$1', $url);
echo $folder ;
FOLDER_NAME
$url = "http://localhost/posts/author/FOLDER_NAME?red=home";
$folder = preg_replace('%.*author/(.*?)\?.*%', '$1', $url);
echo $folder ;
FOLDER_NAME