doutan2228 2013-01-23 08:44
浏览 19

在自由文本中创建网址链接[重复]

Possible Duplicate:
Linkify PHP text

Hi I have a field from a database that contains http links as well as normal text.

I need to find out a way to display this information using PHP to show Text and a link when applicable.

the following is my sql query:

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

the output of this sql statement is:

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

I need to display the http://blahblack.html as a link at the moment it is displaying as normal text.

Thanks!

  • 写回答

1条回答 默认 最新

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

    this might do the job

    example usage: $str = 'this is a random string which contains a link http://www.yahoo.com';

    echo hyperlink($str);

    评论

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数