Changeset 4385

Show
Ignore:
Timestamp:
10/13/06 06:01:14 (2 years ago)
Author:
markjaquith
Message:

make_clickable() now faster and supports more link positions, from mdawaffe and myself. fixes #3228

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2.0/wp-includes/functions-formatting.php

    r4319 r4385  
    590590} 
    591591 
    592 function make_clickable($ret) { 
     592function make_clickable_mine4($ret) { 
    593593    $ret = ' ' . $ret; 
    594     $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "$1<a href='$2' rel='nofollow'>$2</a>", $ret); 
    595     $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "$1<a href='http://$2' rel='nofollow'>$2</a>", $ret); 
    596     $ret = preg_replace("#(\s)([a-z0-9\-_.]+)@([^,< \n\r]+)#i", "$1<a href=\"mailto:$2@$3\">$2@$3</a>", $ret); 
    597     $ret = substr($ret, 1); 
     594    // in testing, using arrays here was found to be faster 
     595    $ret = preg_replace( 
     596        array( 
     597            '#([\s>])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is', 
     598            '#([\s>])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is', 
     599            '#([\s>])([a-z0-9\-_.]+)@([^,< \n\r]+)#i'), 
     600        array( 
     601            '$1<a href="$2" rel="nofollow">$2</a>', 
     602            '$1<a href="http://$2" rel="nofollow">$2</a>', 
     603            '$1<a href="mailto:$2@$3">$2@$3</a>'),$ret); 
     604    // this one is not in an array because we need it to run last, for cleanup of accidental links within links 
     605    $ret = preg_replace("#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i", "$1$3</a>", $ret); 
    598606    $ret = trim($ret); 
    599607    return $ret;