问题描述
这就是我所拥有的
echo '<button><a href="'.$_SERVER['REQUEST_URI'].'&startrow='.($startrow+100).'">Next 100</a></button>';
我的网址中有2个参数,一个是Campaign,第二个是startrow,如何才能从网址中删除"startrow"参数及其值.我想要这样的东西.
I have 2 parameters in my url one is campaign, second is startrow, how can I just remove 'startrow' parameter and its value from the url. I want something like this.
echo '<button><a href="'.REMOVE &startrow=x($_SERVER['REQUEST_URI']).'&startrow='.($startrow+100).'">Next 100</a></button>';
当我按下下一个100按钮时,页面会重新加载,并在url中添加了startrow参数,因此,如果我按5次下一个100按钮,则我的URL中有5个startrow参数,因此我想删除上一个startrow参数首先,然后添加新的
When I press the next 100 button, the page reloads and it adds startrow parameter in the url hence if I pressed next 100 button 5 times, I have 5 startrow paramter in the url, so I want to remove the previous startrow parameter first then add the new one
我的实际网址::enquirytable.php/campaign = all& startrow = 100
My actual url: enquirytable.php/campaign=all&startrow=100
当我单击下一个100"按钮时:enquirytable.php/campaign = all& startrow = 100& startrow = 200
When I click on Next 100 button: enquirytable.php/campaign=all&startrow=100&startrow=200
我想要的:enquirytable.php/campaign = all& startrow = 200
What I want: enquirytable.php/campaign=all&startrow=200
推荐答案
可能很长的路要走,但是您可以尝试这种方式.在这里,我们使用parse_url
和parse_str
来实现所需的输出.
Probably the long way, but you can try this way. Here we are using parse_url
and parse_str
to achieve desired output.
<?php
$url="http://www.example.com/some/path?startrow=100&campaign=abc";
$parameter="startrow";
echo change_url_parameter($url,$parameter,200);
function change_url_parameter($url,$parameter,$parameterValue)
{
$url=parse_url($url);
parse_str($url["query"],$parameters);
unset($parameters[$parameter]);
$parameters[$parameter]=$parameterValue;
return $url["path"]."?".http_build_query($parameters);
}
这篇关于PHP:更改URL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!