我使用这个preg_replace来查找tweet文本中的链接,它忠实地返回一个HTML链接,但我想知道是否有可能,在同一行中,从链接文本中丢失http://。例如:
$output .= preg_replace('@(https?://([-'w'.]+[-'w])+(:'d+)?(/(['w/_'.#-]*('?'S+)?[^'.'s])?)?)@', '<a target="blank" rel="nofollow" href="$1" target="_blank">$1</a>', $status->text);
可能返回:
<a target="blank" rel="nofollow" href="https://kanyewest.com/">https://kanyewest.com</a>
但是我真的希望它返回:
<a target="blank" rel="nofollow" href="https://kanyewest.com/">kanyewest.com</a>
您可以直接使用子字符串。http://php.net/manual/en/function.substr.php