Magic trick to get the correct url?
<p>I am about to make a system that automaticly puts <code>&amp;pni=something</code> behind an URL. It would be easy if the url just was <em><a href="http://t.co/something.php">http://t.co/something.php</a></em> with "?pni=...." but users can also have <em><a href="http://t.co/something.php?myown=paramater">http://t.co/something.php?myown=paramater</a></em> and then the system should add <code>&amp;</code> instead of <code>?</code></p>

<p>How can I put the <code>pni</code> parameter behind the URL and to be valid every time? I've tried this without luck.</p>

<pre><code>&lt;?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&amp;",
  "http://t.co/something.php?w=23&amp;dfdf=",
  "http://t.co/something.php?",
  "http://t.co/something.php",
  "http://t.co/something",
  "http://t.co/something.php?w=23&amp;dfdf=34&amp;hvem",
);

foreach ( $urls as $url):
  echo print_r(nice($url)) . "&lt;br/&gt;";
endforeach;
?&gt;
</code></pre>
