add 文章中超链接新窗口打开

This commit is contained in:
浪子 2024-07-11 09:26:39 +08:00
parent ada941a0b0
commit 52cd510586
1 changed files with 3 additions and 4 deletions

View File

@ -70,15 +70,14 @@ function img_postthumb($cid) {
return ""; // 没有匹配到图片URL返回空字符串 return ""; // 没有匹配到图片URL返回空字符串
} }
} }
//文章目录功能-给文章内标题加上id //文章目录功能-给文章内标题加上id+超链接新窗口打开
function addHeaderLinks($text) function addHeaderLinks($text) {
{
return preg_replace_callback('/<h([1-6])>(.*?)<\/h\1>/', function ($matches) { return preg_replace_callback('/<h([1-6])>(.*?)<\/h\1>/', function ($matches) {
$level = $matches[1]; $level = $matches[1];
$title = $matches[2]; $title = $matches[2];
$id = htmlspecialchars(strip_tags($title), ENT_QUOTES, 'UTF-8'); $id = htmlspecialchars(strip_tags($title), ENT_QUOTES, 'UTF-8');
return sprintf('<h%s id="%s"><a href="#%s" title="%s">%s</a></h%s>', $level, $id, $id, $title, $title, $level); return sprintf('<h%s id="%s"><a href="#%s" title="%s">%s</a></h%s>', $level, $id, $id, $title, $title, $level);
}, $text); }, preg_replace('/<a(?! href="#)(.*?)>/', '<a$1 target="_blank">', $text));
} }
//文章最后修改时间 //文章最后修改时间
function get_last_modified_time($postId) { function get_last_modified_time($postId) {