电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> PHP>>把http://开头的字符串转变成一个WEB连接:

把http://开头的字符串转变成一个WEB连接

来源:www.cncfan.com | 2006-1-11 | (有1774人读过)


 <?
function parse_body($str="") {
$str_array = split (" ",$str);
$sz = sizeof ($str_array);

for ($i = 0; $i < $sz; $i++)
{
if (strstr($str_array[$i], "http://"))
$fr = sprintf ("%s <a href='%s'>%s</a>", $fr, $str_array[$i], $str_array[$i]);
else if (strstr($str_array[$i], "@"))
{
if (strstr($str_array[$i], "."))
$fr = sprintf ("%s <a href='mailto:%s'>%s</a>", $fr, $str_array[$i], $str_array[$i]);
else
$fr = sprintf ("%s %s", $fr, $str_array[$i]);
}
else
$fr = sprintf ("%s %s", $fr, $str_array[$i]);
}
return $fr;
}
?>
Use this function to parse a string for url or mailto addresses. If there is a @ sign and a . it replaces it with
mailt:(that string),
and also looks for http://

Use in the following format:
$new_str = parse_body($str);
echo("$str");
PHP热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2023 电脑爱好者 版权所有 备案号:鲁ICP备09059398号