I figured I should work on another code example since it’s been a while! On one of my sites I needed to convert URLs to be active anchor links. Along with being active anchor links, I thought it would be cool to convert eBay URLs to automatically contain the rover code. Now, all I need to do is paste a straight eBay link to a listing and it will automatically be set to go.
I do this with two custom functions convertEbay() and change_string(). change_string() has a very powerful function called preg_replace_callback() which detects if there is a URL and passes it to the convertEbay() using the callback argument. I store my rover portion as a PHP constant.
function convertEbay($inLink){
$encodeLink = urlencode($inLink[0]);
$out = eregi_replace("(.*cgi.ebay.com.*|.*cgi.ebay.co.uk.*)",ROVER.$encodeLink,$inLink[0]);
$out = "<a href=\"".rtrim($out,‘.’)."\" target=\"_blank\">".$inLink[0]."</a>";
return $out;
}
function change_string($str){
$str = trim($str);
$str = preg_replace_callback(
"/(((f|ht){1}tp:\/\/)[-a-zA-Z0-9@:%\|_\+.~#?&\/\/=]+)/",
"convertEbay",
$str
);
return $str;
}
?>
Incoming search terms:
- roverize links
Related posts:
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.