@@ -278,33 +278,26 @@ function _auto_link_urls($text, $href_options = array(), $truncate = false, $tru
278278{
279279 $ href_options = _tag_options ($ href_options );
280280
281- $ callback_function = '
282- if (preg_match("/<a\s/i", $matches[1]))
283- {
284- return $matches[0];
285- }
286- ' ;
281+ $ callback_function = function ($ matches ) use ($ href_options , $ truncate , $ truncate_len , $ pad ) {
282+ if (preg_match ("/<a\s/i " , $ matches [1 ]))
283+ {
284+ return $ matches [0 ];
285+ }
287286
288- if ( $ truncate )
289- {
290- $ callback_function .= '
291- else if (strlen($matches[2].$matches[3] ) > ' . $ truncate_len. ' )
287+ $ text = $ matches [ 2 ] . $ matches [ 3 ];
288+ $ href = ( $ matches [ 2 ] == " www. " ? " http://www. " : $ matches [ 2 ]) . $ matches [ 3 ];
289+
290+ if ($ truncate && strlen ($ text ) > $ truncate_len )
292291 {
293- return $matches[1]. \' <a href=" \' .($matches[2] == "www." ? "http://www." : $matches[2]).$matches[3]. \' " ' . $ href_options . ' > \' . substr($matches[2].$matches[3] , 0, ' . $ truncate_len. ' ). \'' . $ pad. ' </a> \' .$matches[4] ;
292+ $ text = substr ($ text , 0 , $ truncate_len). $ pad ;
294293 }
295- ' ;
296- }
297294
298- $ callback_function .= '
299- else
300- {
301- return $matches[1]. \'<a href=" \'.($matches[2] == "www." ? "http://www." : $matches[2]).$matches[3]. \'" ' .$ href_options .'> \'.$matches[2].$matches[3]. \'</a> \'.$matches[4];
302- }
303- ' ;
295+ return sprintf ('%s<a href="%s"%s>%s</a>%s ' , $ matches [1 ], $ href , $ href_options , $ text , $ matches [4 ]);
296+ };
304297
305298 return preg_replace_callback (
306299 SF_AUTO_LINK_RE ,
307- create_function ( ' $matches ' , $ callback_function) ,
300+ $ callback_function ,
308301 $ text
309302 );
310303}
0 commit comments