龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

php ereg() 着色返回显示匹配结束

时间:2014-07-25 03:03来源:网络整理 作者:网络 点击:
分享到:
ereg() 着色返回显示匹配结束 [代码片段(30行)]
function replace($str)
{   
    static $color=0;
    $color+=50;
    return "<font style=\\"color:rgb(255,".$color.",33)\\">".$str."</font>";
}

if(  @ereg($match,$str,$array) )
    {
        if(count($array)>1)
        { 
            $string=$str;
            $pos=strpos($string,$array[1]);
            $string=substr_replace($string,replace($array[1]),$pos,strlen($array[1]));
            $pos=$pos+strlen(replace($array[1]));
            echo $string.'<br/>';

            for($i=2;$i<count($array);$i++)
            { 
                $pos=strpos($string,$array[$i],$pos);
                $string=substr_replace($string,replace($array[$i]),$pos,strlen($array[$i]));
                $pos=$pos+strlen(replace($array[$i]));
                echo $string.'<br/>';
            }
        } //end if(count($array)>1)

        print_r($array);

    }
//该片段来自于http://outofmemory.cn
精彩图集

赞助商链接