php中将网址转换为超链接的函数

 2025-01-15  阅读 327  评论 8  点赞 163

摘要:复制代码 代码如下: function showtext($text){ $search = array('|(http://[^ ]+)|', '|(https://[^ ]+)|', '|(www.[^ ]+)|'); $replace = array('$1', '$1', '$1'); $text = preg_replace($search, $replace, $text); return $text; }
复制代码 代码如下:

function showtext($text){
$search = array('|(http://[^ ]+)|', '|(https://[^ ]+)|', '|(www.[^ ]+)|');
$replace = array('<a href="$1" target="_blank">$1</a>', '<a href="$1" target="_blank">$1</a>', '<a href="http://$1" target="_blank">$1</a>');
$text = preg_replace($search, $replace, $text);
return $text;
}

标签:phpphp教程

评论列表:

显示更多评论

发表评论:

管理员

承接各种程序开发,外贸网站代运营,外贸网站建设等项目
  • 内容2462
  • 积分67666
  • 金币89666

Copyright © 2024 LS'Blog-保定PHP程序员老宋个人博客 Inc. 保留所有权利。 Powered by LS'blog 3.0.3

页面耗时0.0270秒, 内存占用1.92 MB, 访问数据库29次

冀ICP备19034377号