0

我有一个这样的字符串:

$str = 'hi, http://www.google.com is a search engine while "http://www.facebook.com" is a social network';

我想将http://www.google.com转换为链接,而不是转换http://www.facebook.com(因为它在引号中)。这是我已经拥有的

$return = preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@', '<a href="$1" target="_blank">$1</a>', $return);
4

1 回答 1

0

Here is you solution

<?php
$str = 'hi, http://www.google.com is a search engine while "http://www.facebook.com" is a social network';
$s=explode(",",$str);
$s[1];
$n=explode(" ",$s[1]);
echo $n[1];
?>
于 2012-08-18T10:58:30.957 回答