将 http:// link 作为文本转换为 href,但不要在末尾包含 <br> 标记
Transform http:// link as text to a href but dont include <br> tag at the end
所以我有这个代码:
preg_replace('/(http[s]?:\/\/[^\s]*[^,\s\.])/i', '<a href=""></a>', $post_text);
它允许我从文本中的 links 创建 hyperlinks。最后 [^,\s\.])
是当有人发布类似 "Oh hey this is nice link http://google.com." 的内容时 - 它在最后删除了点(除其他外)并且不包括她在创建 ahref 中。
我的问题是在那之后我有一个换行符 link。例如有人发帖
“哦嘿这很好linkhttp://google.com
然后我的脚本被输入
"Oh hey this is nice link http://google.com<br>"
突然 <br>
包含在 link 中,我很难过,因为这不是我想要的 :(
我试过了
preg_replace('/(http[s]?:\/\/[^\s]*[^,\s\.<br>])/i', '<a href=""></a>', $post_text);
但显然不正确。
有什么帮助吗?
(http[s]?:\/\/[^\s<>]*[^,\s\.<>])
您好,您只需添加“< >”
在你上一个正则表达式中,它匹配 <br>
第一个 [^\s]*
所以我有这个代码:
preg_replace('/(http[s]?:\/\/[^\s]*[^,\s\.])/i', '<a href=""></a>', $post_text);
它允许我从文本中的 links 创建 hyperlinks。最后 [^,\s\.])
是当有人发布类似 "Oh hey this is nice link http://google.com." 的内容时 - 它在最后删除了点(除其他外)并且不包括她在创建 ahref 中。
我的问题是在那之后我有一个换行符 link。例如有人发帖
“哦嘿这很好linkhttp://google.com
然后我的脚本被输入
"Oh hey this is nice link http://google.com<br>"
突然 <br>
包含在 link 中,我很难过,因为这不是我想要的 :(
我试过了
preg_replace('/(http[s]?:\/\/[^\s]*[^,\s\.<br>])/i', '<a href=""></a>', $post_text);
但显然不正确。
有什么帮助吗?
(http[s]?:\/\/[^\s<>]*[^,\s\.<>])
您好,您只需添加“< >”
在你上一个正则表达式中,它匹配 <br>
第一个 [^\s]*