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" rel="nofollow">http://www.example.com</a></p></li>
<li><p><a href="http://www.example.com/a/" rel="nofollow">http://www.example.com/a/</a></p></li>
<li><p><a href="http://www.example.com/a/?q1=one" rel="nofollow">http://www.example.com/a/?q1=one</a></p></li>
<li><p><a href="http://www.example.com/a.html" rel="nofollow">http://www.example.com/a.html</a></p></li>
<li><p><a href="http://www.example.com/a.html?q1=one" rel="nofollow">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" rel="nofollow">http://www.example.com/?q2=two</a></p></li>
<li><p><a href="http://www.example.com/a/?q2=two" rel="nofollow">http://www.example.com/a/?q2=two</a></p></li>
<li><p><a href="http://www.example.com/a/?q1=one&amp;q2=two" rel="nofollow">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" rel="nofollow">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" rel="nofollow">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>
