本文共 655 字,大约阅读时间需要 2 分钟。
这个函数可以为组成一个链接,第一个参数是链接的URL,第二个参数是抛文本。
最后生成
function parseurl($url, $text) {
if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k|thunder|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {
$url = $matches[0];
$length = 65;
if(strlen($url) > $length) {
$text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
}
return '';
} else {
$url = substr($url, 1);
if(substr(strtolower($url), 0, 4) == 'www.') {
$url = 'http://'.$url;
}
return '';
}
}
echo parseurl('http://enenba.com/?post=97','本文链接名');
?>
这个函数很好用是吧,可以为你想要加的链接符上想用调的URL,后台可以轻易地修改URL的类型,在模板层可以不用考虑输出的URL类型。
希望对大家有用。
end
转载地址:https://blog.csdn.net/weixin_33744799/article/details/115737114 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!