-3

可能重复:
链接 PHP 文本

嗨,我有一个来自数据库的字段,其中包含 http 链接以及普通文本。

我需要找到一种使用 PHP 显示此信息的方法,以便在适用时显示文本和链接。

以下是我的 sql 查询:

  $sql =
   "select bw_supporting_doc
    from cm3rm2 with(nolock)
    where number = '$id'";

此 sql 语句的输出为:

Please find below the link to the FSS: http://blahblack.html

我需要在http://blahblack.html显示为普通文本时将其显示为链接。

谢谢!

4

1 回答 1

0
function hyperlink($text){
    $text = preg_replace("#(http://)+?([.]?[a-zA-Z0-9_/-])*#", "<a href=\"\\0\" target=\"_blank\">\\0</a>", $text);
    return $text;
}

这可能会完成这项工作

示例用法: $str = 'this is a random string which contains a link http://www.yahoo.com';

echo hyperlink($str);

于 2013-01-23T08:50:17.603 回答