From 91a97937f785f013d6304478c1e4df88691c1193 Mon Sep 17 00:00:00 2001 From: marcus Date: Sat, 28 Feb 2009 22:28:03 +0000 Subject: Closes #665: Using a bit of preg callback magic to do encoding and href encoding in one pass. git-svn-id: https://code.elgg.org/elgg/trunk@3002 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/input.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'engine') diff --git a/engine/lib/input.php b/engine/lib/input.php index 80329462e..dd0480d9f 100644 --- a/engine/lib/input.php +++ b/engine/lib/input.php @@ -107,6 +107,7 @@ return $path; } + /** * Takes a string and turns any URLs into formatted links @@ -115,17 +116,17 @@ * @return string The output stirng with formatted links **/ - function parse_urls($text) { - - if (preg_match_all('/(?"\'\!\(\)]+)/ie', $text, $urls)) { - - foreach (array_unique($urls[1]) AS $url){ - $urltext = str_replace('/', '/', $url); - $text = str_replace($url, ''. $urltext .'', $text); - } - } - - return $text; + function parse_urls($text) { + + return preg_replace_callback('/(?"\'\!\(\)]+)/i', + create_function( + '$matches', + ' + $url = $matches[1]; + $urltext = str_replace("/", "/", $url); + return "$urltext"; + ' + ), $text); } function autop($pee, $br = 1) { -- cgit v1.2.3