Translate

2012年2月22日 星期三

php 過濾不要的字元或符號


範例

$str = "wow!h@e#l%l^o"; //需要過濾的字串

$del_char = array('~','!','@','#','%','^','wow');  //需要濾掉的字元

 foreach($del_char as $v)
    $str = str_replace($v,"",$str);
   echo $str;


2015/09/02

 因為效能關係 有發現了 新的寫法



   <?php
$trans = array( "hello" => "hi""hi" => "hello");
echo 
strtr("hi all, I said hello"$trans);?>

輸出結果: hello all, I said hi

來源:http://php.net/manual/en/function.strtr.php

沒有留言:

張貼留言