教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php查找字符串中http地址

php查找字符串中http地址

发布时间:2018-02-10   编辑:jiaochengji.com
本文介绍下php查找字符串中的http地址并加以转换的代码,学习下php字符串查找的方法,有需要的朋友参考下。

例子,在字符串中查找http地址并转换。
<?php
//php字符串查找
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;
}

参考文章:

php strstr查找字符串中是否包含某些字符 php 查找字符串常用函数说明 php字符串查找函数(strrpos与strchr) php字符串查找函数strstr()、strrchr()实例 php字符串比较与查找方法详解 php查找、替换字符串中http地址的代码分享 php中用于查找字符串的常用函数

您可能感兴趣的文章:
php查找字符串中http地址
php查找、替换字符串中http地址的代码分享
php字符串查找函数strstr()、strrchr()实例
php 查找字符串常用函数说明
php 操作IP地址库QQWry.dat的实例分享
php字符串查找函数(strrpos与strchr)
PHP字符串函数与使用分析
php字符串函数有哪些
php字符串操作函数入门篇
php5 字符串处理函数汇总

关键词: php字符串  字符串查找   
[关闭]
~ ~