Assuming I have an Amazon product URL like so
http://www.amazon.com/Kindle-Wireless-Reading-Display-Generation/dp/B0015T963C/ref=amb_link_86123711_2?pf_rd_m=ATVP
@Gumbo: Your code works great!
//JS Test: Test it into firebug.
url = window.location.href;
url.match("/([a-zA-Z0-9]{10})(?:[/?]|$)");
I add a php function that makes the same thing.
function amazon_get_asin_code($url) {
global $debug;
$result = "";
$pattern = "([a-zA-Z0-9]{10})(?:[/?]|$)";
$pattern = escapeshellarg($pattern);
preg_match($pattern, $url, $matches);
if($debug) {
var_dump($matches);
}
if($matches && isset($matches[1])) {
$result = $matches[1];
}
return $result;
}