preg_match vs parse_url which is faster?
Im trying to remap all urls with a refcode
Code:
<?php
$url = 'http://themeforest.net/item/simple-mobile-template/112089';
function refcode($url) {
$sites = array('themeforest.net','activeden.net','audiojungle.net','videohive.net','graphicriver.net','3docean.net','codecanyon.net');
$refcode = '/?ref=chrismccoy';
$parsed = parse_url($url);
if (in_array($parsed['host'],$sites)) {
return $url . $refcode;
}
}
echo refcode($url);
?>
or
Code:
<?
$st = "/?ref=lorem";
$url = "http://themeforest.net/item/studio960-wordpress-by-cudazi/111595";
$link = preg_replace('/.*?<a [^>]*href[^>]*'.preg_quote($url,"/").'[^>]*>(.*?)<\/a>.*/is','\1',$url.$st);
echo preg_quote($url);
?>
sample #2 will scan for all links (will be in the body of a blog post), which I need it to do.
anyone got other suggestions?
:thumbsup
|