Should I use str_replace instead of substr?
05:33 02 Aug 2013

I'm using a data feed plugin that has a custom PHP function that allows me to rewrite every Buy_URL in the feed. Say, for example, one of the original Buy_URLs is this:

http://www.affiliatecompa.com/product/clean.com?ref=ab

I want to rewrite the beginning and the end of the URL with

"http://www.dsqce.com/click-111111-1111XX111?url=http%3A%2F%2Fwww.affiliatecompa.com"

and

"laik"` respectively. so that it should become:

http://www.dsqce.com/click-111111-1111XX111?url=http%3A%2F%2Fwww.affiliatecompa.com/product/clean.com?ref=laik

I contacted the author of the plugin, and he told me to put the following code in the function.php file in my theme and then call the function in the plugin:

function WOKI_Change_Url($x) {
    $y = substr($x, 29);
    $y = substr($y, -2);
    return "http://www.dsqce.com/click-111111-1111XX111?url=http%3A%2F%2Fwww.affiliatecompa.com" . $y . 'laik';
}

Apparently, it doesn't work, because it removes any other part of the URL and every Buyurl has now become:

http://www.dsqce.com/click-111111-1111XX111?url=http%3A%2F%2Fwww.affiliatecompa.comlaik

I suspect that substr isn't right for what I want to do in this case. Should I use str_replace instead in the function?

php string replace