dimanche 19 avril 2015

Is using strpos() before preg_replace() faster?

Lets say we use this code for millions if posts:



public static function makeClickableLinks($s) {
return preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@', '<a href="$1" target="_blank">$1</a>', $s);
}


Now assume that only 10% if all posts contain links, would it be faster to check strpos($string, 'http') !== false before calling makeClickableLinks()?


Aucun commentaire:

Enregistrer un commentaire