Maison >développement back-end >tutoriel php > PHP 正则表达式、反则轮换字符串
PHP 正则表达式、反则替换字符串
代码:
?
? //反则,保留除了A-Za-z0-9@\*的字符
??? $word = "6915-615@JPY11890*5822?" ;
??? $par = array('/[^A-Za-z0-9@\*]/');?
??? $word = preg_replace($par, "", $word);
??? echo ??? $word;
??? echo "
";
??? //正则,剔除A-Za-z0-9@\*字符
??? $word = "6915-615@JPY11890*5822?" ;
??? $par = array('/[A-Za-z0-9@\*]/');?
??? $word = preg_replace($par, "", $word);
??? echo ??? $word;
结果:
?
6915615@JPY11890*5822
-