识别一段字符串中的链接
/**
* 查找并替换,文字中存在的URL,为URL链接
* @return array
*/
public static function replaceURL($stringContentUrlPara) {
$stringContent = $stringContentUrlPara;
// 得到目的域名:(com\.cn|com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)
$stringAllowDomainSuffix = str_ireplace( ".", "\.", implode('|', self::allowDomainSuffix()) );
// if ($result = filter_var($stringContentUrlPara, FILTER_VALIDATE_URL))
if ($checkHaveURL = preg_match( "/(((ht|f)tp(s?))\:\/\/)+(www\.|[a-zA-Z]*\.)[a-zA-Z0-9\-]+(" . $stringAllowDomainSuffix . ")(\:[0-9]+)?(\/+[a-zA-Z0-9\-_\.\=\?\&]++)/Ui", $stringContentUrlPara, $URL ))
{ // 如果是一个url图片地址
$stringContent = str_ireplace($URL[0], "[". $URL[0] ."]", $stringContentUrlPara);
}
return $stringContent;
}
* 查找并替换,文字中存在的URL,为URL链接
* @return array
*/
public static function replaceURL($stringContentUrlPara) {
$stringContent = $stringContentUrlPara;
// 得到目的域名:(com\.cn|com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)
$stringAllowDomainSuffix = str_ireplace( ".", "\.", implode('|', self::allowDomainSuffix()) );
// if ($result = filter_var($stringContentUrlPara, FILTER_VALIDATE_URL))
if ($checkHaveURL = preg_match( "/(((ht|f)tp(s?))\:\/\/)+(www\.|[a-zA-Z]*\.)[a-zA-Z0-9\-]+(" . $stringAllowDomainSuffix . ")(\:[0-9]+)?(\/+[a-zA-Z0-9\-_\.\=\?\&]++)/Ui", $stringContentUrlPara, $URL ))
{ // 如果是一个url图片地址
$stringContent = str_ireplace($URL[0], "[". $URL[0] ."]", $stringContentUrlPara);
}
return $stringContent;
}