【发布时间】:2019-12-21 14:39:18
【问题描述】:
我有这个功能来识别和转换主题标签、表情符号等
function convert_text($str) {
$regex = "/[@#](\w+)/";
//type and links
$hrefs = [
'#' => 'hashtag.php?hashtag',
'@' => 'user.php?user'
];
$result = preg_replace_callback($regex, function($matches) use ($hrefs) {
return sprintf(
'<a href="%s=%s">%s</a>',
$hrefs[$matches[0][0]],
$matches[1],
$matches[0]
);
}, $str);
//$result = preg_replace("/U\+([A-F0-9]{5})/", '\u{${1}}', $result);
$result = preg_replace('/U\+([A-F0-9]{5})/', '<span style="font-size:30px;">&#x\\1;</span>', $result);
return ($result);
}
我想让它从文本中识别http:// 和https://,然后转换为:
<a href="http://link.com">http://link.com</a>
如何在函数内部实现呢?
【问题讨论】:
-
转换表情符号有什么意义?他们已经是人物了。
-
该功能已经识别和转换表情符号,我想让它重新转换和转换链接
httphttps -
我在研究这个问题时看到了那个页面。它做了一件必需的事情,但该技术需要正确集成到 OP 的现有脚本中,以提供 OP 所需的结果。