<HTML>
<p>The following link should change to "http://www.emarketbuilders.com/?var=val."</p>
<a href="http://www.emarketbuilders.com">Link without original querystring</a>
<br />
<p>The following link should change to "http://www.emarketbuilders.com/?var=val&var1=val1."</p>
<a href="http://www.emarketbuilders.com/?var1=val1">Link with original querystring</a>
<br />
<p>So, there should be two separate variables two append for two different conditions. The questions are: </p>
<ul>
<li>How do I find URL's from a variable containing HTML (like this one).</li>
<li>How do I replace the URL's based on the result?</li>
</ul>
<p>Thank you!</p>
</HTML>
ASKER
$tmp = preg_replace('/"([a-z]+:\/\/[^\?"]+\?)([^"]*)"/', "$1var=val&$2", $text);
$result = preg_replace('/"([a-z]+:\/\/[^\?"]+)"/', "$1?var=val", $tmp);
ASKER
ASKER
$tmp = preg_replace('/("[a-z]+:\/\/[^\?"]+\?)([^"]*")/', "$1var=val&$2", $text);
$result = preg_replace('/("[a-z]+:\/\/[^\?"]+)(")/', "$1?var=val$2", $tmp);
ASKER
ASKER
ASKER
ASKER
ASKER
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.
TRUSTED BY
Open in new window