PDA

View Full Version : Parse Amazon LInk into Affiliate LInk



Chris
08-15-2006, 02:22 PM
Feedburner has a feature where any amazon link in your feed is automatically turned into an affiliate link.

Has anyone seen php source code for doing this anywhere? I don't want to have to do it from scratch if I don't have it. I imagine you just need to parse out the ASIN from the link and put it into an affiliate link.

Emancipator
08-15-2006, 04:22 PM
str_replace I imagine would do the trick nicely since the asin is always in the same position.

Chris
08-15-2006, 04:26 PM
Not always, Amazon has changed their URL structure a lot.

I went with this:




$url_array = explode("/",$url);

foreach ($url_array as $v) {
if(ereg("^[A-Z0-9]*$", $v)){
$url = "http://www.amazon.com/exec/obidos/ASIN/".$v."/ref=nosim/everythingshak06";
}

}

Emancipator
08-15-2006, 04:57 PM
exactly what i was thinking.