append query string to any form of URL
<p>I have one question for you all:</p>

<p>I will ask user to input URL in a text-box and need to append query string to it.</p>

<p>Possible values of URLs can be like</p>

<ol>
<li><p><a href="http://www.example.com">http://www.example.com</a></p></li>
<li><p><a href="http://www.example.com/a/">http://www.example.com/a/</a></p></li>
<li><p><a href="http://www.example.com/a/?q1=one">http://www.example.com/a/?q1=one</a></p></li>
<li><p><a href="http://www.example.com/a.html">http://www.example.com/a.html</a></p></li>
<li><p><a href="http://www.example.com/a.html?q1=one">http://www.example.com/a.html?q1=one</a></p></li>
</ol>

<p>Now I need to add query string to it like "q2=two", so that output would be like:</p>

<ol>
<li><p><a href="http://www.example.com/?q2=two">http://www.example.com/?q2=two</a></p></li>
<li><p><a href="http://www.example.com/a/?q2=two">http://www.example.com/a/?q2=two</a></p></li>
<li><p><a href="http://www.example.com/a/?q1=one&amp;q2=two">http://www.example.com/a/?q1=one&amp;q2=two</a></p></li>
<li><p><a href="http://www.example.com/a.html?q2=two">http://www.example.com/a.html?q2=two</a></p></li>
<li><p><a href="http://www.example.com/a.html?q1=one&amp;q2=two">http://www.example.com/a.html?q1=one&amp;q2=two</a></p></li>
</ol>

<p>How can I achieve the following using PHP, please help guys.</p>

<p>Thanks</p>
