make_clickable()将纯文本中的URI转换成HTML链接

目录

描述

译文

将普通文本URL转换成HTML链接。

可以转换URL,www,ftp和电子邮件地址等。

原文

 纯文本中的URI转换成HTML链接。

将转换 URI,www,FTP 和  地址,并且修正链接中的链接。

make_clickable() 描述

用法

<?php make_clickable$text ?>

make_clickable() 用法

参数

$text

(string) (必填) 将转换成 点击的文本。

默认值: None

make_clickable() 参数

返回值

(string)

链接转换成可点击的 HTML 代码。

make_clickable() 返回值

示例

Display all URLs in clickable links

make_clickable() 示例

注意

This function can be fed long strings with URIs and email links and will convert them into clickable links. You are not limited to feeding it just the link text itself (see the long string in the example above).

make_clickable() 注意

历史

添加于 版本: 0.71

make_clickable() 历史

源文件

make_clickable() 函数的代码位于
wp-includes/formatting.php.

' === strtolower( $piece ) ) && $nested_code_pre )
$nested_code_pre--;

if ( $nested_code_pre || empty( $piece ) || ( $piece[0] === '<' &&="" !="" preg_match(="">< strlen(="" $piece="" )="" )="" {="" ...="" break="" it="" up="" foreach="" (="" _split_str_by_whitespace(="" $piece,="" 2100="" )="" as="" $chunk="" )="" {="" 2100:="" extra="" room="" for="" scheme="" and="" leading="" and="" trailing="" paretheses="" if="" (="" 2101="">< strlen(="" $chunk="" )="" )="" {="" $r="" .="$chunk;" too="" big,="" no="" whitespace:="" bail.="" }="" else="" {="" $r="" .="make_clickable(" $chunk="" );="" }="" }="" }="" else="" {="" $ret=" $piece " ;="" pad="" with="" whitespace="" to="" simplify="" the="" regexes="" $url_clickable='~ ([\s(<.,;:!?]) # 1: Leading whitespace, or punctuation ( # 2: URL [\w]{1,20}+:// # Scheme and hier-part prefix (?=S{1,2000}s) # Limit to URLs less than about 2000 characters long [\w\x80-\xff#%\~/@\[\]*(+=&$-]*+ # Non-punctuation URL character (?: # Unroll the Loop: Only allow puctuation URL character if followed by a non-punctuation URL character [' .,;:!?)]="" #="" punctuation="" url="" character="" [\w\x80-\xff#%\~/@\[\]*(+="&$-]++" #="" non-punctuation="" url="" character="" )*="" )="" ()?)="" #="" 3:="" trailing="" closing="" parenthesis="" (for="" parethesis="" balancing="" post="" processing)="" ~xs';="" the="" regex="" is="" a="" non-anchored="" pattern="" and="" does="" not="" have="" a="" single="" fixed="" starting="" character.="" tell="" pcre="" to="" spend="" more="" time="" optimizing="" since,="" when="" used="" on="" a="" page="" load,="" it="" will="" probably="" be="" used="" several="" times.="" $ret="preg_replace_callback(" $url_clickable,="" '_make_url_clickable_cb',="" $ret="" );="" $ret="preg_replace_callback(" '#([s="">])((www|ftp).[w\x80-\xff#$%&~/.-;:=,?@[]+]+)#is', '_make_web_ftp_clickable_cb', $ret );
$ret = preg_replace_callback( '#([s>])([.0-9a-z_+-]+)@(([0-9a-z-]+.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret );

$ret = substr( $ret, 1, -1 ); // Remove our whitespace padding.
$r .= $ret;
}
}

// Cleanup of accidental links within links
return preg_replace( '#(]+?>|>))]+?>([^>]+?)#i', "$1$3", $r );
}

make_clickable() 源文件