Replace one URL with another without regex
<p>I'm trying to replace some URLs in a database (wordpress) with another, but it's tricky because a lot of the URLs are redirects. I'm trying to either replace the URL with the redirected URL, or with a URL of my choosing, based on the result. I can get the matching done without any problems, but I can't replace it. I've tried str_replace, but it doesn't seem to replace the URLs. When I try preg_replace, it will give "Warning: preg_replace(): Delimiter must not be alphanumeric or backslash". Can anyone point me in the right way to do this?</p>

<pre><code>if(preg_match($url_regex,$row['post_content'])){
    preg_match_all($url_regex,$row['post_content'],$matches);

    foreach($matches[0] as $match){
        echo "{$row['ID']} \t{$row['post_date']} \t{$row['post_title']}\t{$row['guid']}";

        $newUrl = NULL;
        if(stripos($url_regex,'domain1') !== false || stripos($url_regex,'domain2') !== false || stripos($url_regex,'domain3') !== false){
            $match = str_replace('&amp;amp;','&amp;',$match);

            $ch = curl_init();
            curl_setopt($ch,CURLOPT_URL,$match);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_HEADER, true);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            $html = curl_exec($ch);
            $newUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);

            if(stripos($newUrl,'domain4') !== false)
                $newUrl = NULL;

        }
        else

        if($newUrl == NULL)
        {   $newUrl = 'http://www.mysite.com/';

        }
        echo "\t$match\t$newUrl";
        $content = str_replace($match,$newUrl,$row['post_content']); 
        echo "\t (" . strlen($content).")";
        echo "\n";

    }
}
</code></pre>
