要使网站嵌入成为可能,以下行会检查是否有http://
或https://
if(preg_match_all('#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', $content, $match )){
但是,我想过滤掉{http:1}之前的"http://
或"https://
等内容。
这是因为图像嵌入的格式为
<img src="http://~~~.jpg">
我想区分图像嵌入和普通网站的嵌入。
答案 0 :(得分:1)
您需要使用look-behind断言
$regex = '/\b(?<!")https?:\/\/[^\s()<>]+(?:\([\w\d]+\)|[^[:punct:]\s]|\/)/';
$links = 'http://www.test.com
"http://www.test.com"';
preg_match_all($regex, $links, $matches);
print_r($matches);
参见 regex demo
PHP (demo)
$ ls -1 /usr/lib/libncurses*
/usr/lib/libncurses.so
/usr/lib/libncurses++.so
/usr/lib/libncurses++w.so
/usr/lib/libncursesw.so
/usr/lib/libncurses++w.so.6
/usr/lib/libncursesw.so.6
/usr/lib/libncurses++w.so.6.0
/usr/lib/libncursesw.so.6.0
答案 1 :(得分:0)
如果您有HTML源,那么您想要使用HTML解析器。解析器将让您区分标签和文本,然后您可以将转换应用于文本。
如果您按原样尝试,那么您还必须担心在HTML中使用URL的所有方式。前面的双引号找不到所有这些。