我即将建立一个自动将&pni=something
放在URL后面的系统。这将是容易,如果该URL仅仅是http://t.co/something.php用“?PNI = ......”,但用户也可以有http://t.co/something.php?myown=paramater然后系统应该增加&
而不是?
获得正确url的魔术?
我怎样才能把pni
URL后面的参数并且每次都有效?我试过这个没有运气。
<?php
function nice($in){
$out = parse_url($in);
return $out['scheme'] . "://" . $out['host'] . $out['path'] . "?" . $out['query'];
}
$urls = array(
"http://t.co/something.php?w=23&",
"http://t.co/something.php?w=23&dfdf=",
"http://t.co/something.php?",
"http://t.co/something.php",
"http://t.co/something",
"http://t.co/something.php?w=23&dfdf=34&hvem",
);
foreach ($urls as $url):
echo print_r(nice($url)) . "<br/>";
endforeach;
?>
[http_build_query](http://php.net/manual/en/function.http-build-query.php)没有做你想做的事吗? – naththedeveloper 2013-05-01 13:49:54
这已经[问及回答](http://stackoverflow.com/q/16013703)。 – HamZa 2013-05-01 13:53:11