Jump to content
新域网络技术论坛

批量替换字符串(数组方式)[PHP]


Jamers
 Share

Recommended Posts

很简单的功能,用preg_replace一次搞定

function cleanstr($str,$ary='') {
    /*
        Jamers 2013.06.27
        清除字符串内无效字符
    */
    $tt = '*,?,-,/,.,:,\\';
    if ($ary != '') $tt = $ary;
    $t = explode(',',$tt);
    $p = array();
    $r = array();
    foreach($t as $v) {
        $p[] = '/\\'.$v.'/';
        $r[] = '';
    }
    return preg_replace($p,$r,$str);
}
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...