You are here:  » search and replace


search and replace

Submitted by dflsports on Sun, 2006-01-22 03:35 in

I beta tested Magic Parser, liked it and bought it :) Now I am inporting datafeeds into mysql. Well now it's time for a new question. Is there a way to do a search and replace before importing the data.

I have many feeds with no affiliate codes, just the url, like http://buyme.com/product.html

I would like to add code like http://affcode.com/buy?=buyme.com/product.html

Can I do this. I'm new to php and mysql and found this page, but not sure how to implement it :(

http://us3.php.net/str_replace

Thank you for your assistance.

Submitted by support on Sun, 2006-01-22 07:59

Hi,

Yes - you could use str_replace on any field in each record within your record handler function before inserting info into a database, for example, suppose that the URL is in the field "DEEPLINK" and you want to make the modification as given in your example:

<?php
function myRecordHandler($record)
{
  
$record["DEEPLINK"] = str_replace("http://","http://affcode.com/buy?=",$record["DEEPLINK"]);
  
// rest of code
}
?>

Hope this helps!

Submitted by dflsports on Wed, 2006-01-25 04:54

It worked, thanks!