【发布时间】:2017-03-01 06:20:59
【问题描述】:
我有一个嵌入 iframe 链接的代码。
$post_contetn = explode('htt',$content);
$content_with_link = $post_contetn[0];
$link = 'htt'.$post_contetn[1];
但问题是,如果我写了
http://www.espn.com was great
然后它链接“很棒”是 $link 的一部分。
如何更改(可能使用正则表达式)以仅包含实际网址?
======
如果我把暹罗的回答结合起来,应该是
$regex = '/https?:\/\/.*?(?=\s)/';
$post_contetn = preg_match($regex, $content, $linkarray);
$content_with_link = $post_contetn[0];
$link = $linkarray[0]
echo $content_with_link;
然后我编辑为
preg_match($regex, $content, $post_contetn);
$content_with_link = $post_contetn[0];
$link = $post_contetn[0]
echo $content_with_link;
但错误仍然出现在回显线。
【问题讨论】: