Hi,
I could use a little help please. I am attempting to append the param k=12345 to each x.swf located between <object> tags. If there is existing params, I need to add one with & and if not then add it with ?. So far I have...
<?php
$patterns[0] = "/(<object>)(.*)(\S\.swf(?=\?)\S+)(.*)(<\/object>)/is";
$patterns[1] = "/(<object>)(.*)(\S\.swf(?!\?))(.*)(\/object>)/is";
$replacements[0] = "\$1\$2\$3&k=12345\$5\$6";
$replacements[1] = "\$1\$2\$3?k=12345\$4\$5";
print preg_replace($patterns, $replacements, $stringin);
?>
Assume that $stringin is the entire html file. The code above only replaces the last matching value-- so...
Html:
<object>
x.swf?testvar=1
x.swf?testvar=1
</object>
returns:
Html:
<object>
x.swf?testvar=1
x.swf?testvar=1&k=12345</object>
I need both x.swf?testvar=1 to change to x.swf?testvar=1&k=12345.
Help.
Thanks.