php查找字符串中的http地址,并转换

来源:互联网 发布:seo外链群发工具 编辑:程序博客网 时间:2024/05/17 06:29
function convertImg($str){$str = preg_replace("/\{([^}]+)\}/",'<div style="border:1px dashed #003366; background-color:#f0f0f0; height:21px; color:#003399">回复:$1</div>',preg_replace("/\[(\d+)\]/",'<img src="/images/face/face$1.jpg"/>',$str));$reg="/http\:\/\/(\w+\.)+(net|com|org|cn|kr|jp|tw)[A-Za-z0-9_&\/\?=]*/i";if(preg_match_all($reg,$str,$out)){for($i=0;$i<count($out[0]);$i++){$link=substr(base64_encode(md5(preg_replace("/http\:\/\//","",$out[0][$i]))),0,10+strlen($str)%10);$str=str_replace($out[0][$i],'<a href="'.$out[0][$i].'">http://'.$link.'</a>',$str);}}return $str;}

我的QQ群:

PHPer&Webgame&移动开发,群号:95303036

原创粉丝点击