Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP从一些变量查询中剪切URL_Php_Url - Fatal编程技术网

PHP从一些变量查询中剪切URL

PHP从一些变量查询中剪切URL,php,url,Php,Url,如果我有如下URL: http://localhost/myfile.php?start=2018&end=2019&page=1&status= 没有人知道如何替换该链接中包含page=的任何单词吗 我想要的结果是: http://localhost/myfile.php?start=2018&end=2019&status= 即使链接是这样的: http://localhost/myfile.php?start=2018&end=2019&status=&page=3 我仍然希望结果没有pa

如果我有如下URL:

http://localhost/myfile.php?start=2018&end=2019&page=1&status=

没有人知道如何替换该链接中包含
page=
的任何单词吗

我想要的结果是:

http://localhost/myfile.php?start=2018&end=2019&status=

即使链接是这样的:

http://localhost/myfile.php?start=2018&end=2019&status=&page=3

我仍然希望结果没有
page
变量和值,因此可能是:
http://localhost/myfile.php?start=2018&end=2019&status=

你知道怎么做吗?特别是没有regex(regex是我最后的选择)

您可以使用,并且:


为了更好地理解示例代码,我建议阅读文档或打印示例代码的变量。

它是字符串吗?没有正则表达式吗?这是非常复杂的,不能确定100%是一个真正的URL还是你得到它作为一个字符串?已同意@InazoPHP已具有和的函数。使用它们。@Blackam哦对不起。。。以前找不到。。。那篇文章正是我需要的!多谢各位
// Your URL
$str = 'http://localhost/myfile.php?start=2018&end=2019&page=1&status=';

// Get parts
$parts = parse_url($str);

// Get array of arguments
parse_str($parts['query'], $args);

// Remove unwanted index
unset($args['page']);

// Rebuild your URL
echo $parts['scheme'] . '://' . $parts['host'] . $parts['path'] . '?' . http_build_query($args);

// Output: http://localhost/myfile.php?start=2018&end=2019&status=