View Single Post
Old 07-08-2010, 06:16 AM  
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,372
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?

__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote