代码:
<?php
$sBin=" this a test file";
echo str_replace( "0", "o", "this is a b00k");
$sBin=str_replace(" ","", $sBin);
print $sBin . "\n\n";
$sBin=" [thi||s a te\\\\st \t . .. f...\\ile\t\n --*....{{() AaBbcccCCC ok.]";
print $sBin . "\n\n";
print preg_replace(' /\\|\n|\\.|\|/',"",$sBin) . " @@@10\n";
print preg_replace(' /\\\\|\n|\\.|\|/',"",$sBin) . " @@@11\n";
print preg_replace(' /[\\\\|\n|\\.|\|]/',"",$sBin) . " @@@12\n";
print preg_replace('/[\\\\\n|\\.\|]/',"",$sBin) . " @@@13\n";
print preg_replace(' /[\\\n\\.\|]/',"",$sBin) . " @@@14\n";
print preg_replace(' /[\\\\\n\\.\|]/',"",$sBin) . " @@@15\n";
print preg_replace('/[\\\\|\n|\\.|\|]/',"",$sBin) . " @@@20\n";
print preg_replace('/[\\\\|\n|\\.|\|a-z]/',"",$sBin) . " @@@21\n";
print preg_replace('/[\\\\|\n|\\.|\|a-z]/i',"",$sBin) . " @@@22\n"; //i:忽略大小写
print preg_replace('/[\\\\|\n|\\.|\|\s]/',"",$sBin) . " @@@30\n"; // \s 代表空格,制表符等
?>
运行结果:
this is a bookthisatestfile
[thi||s a te\\st . .. f...\ile
--*....{{() AaBbcccCCC ok.]
[this a te\\st f\ile
--*{{() AaBbcccCCC ok] @@@10
[this a test file --*{{() AaBbcccCCC ok] @@@11
[this a test file --*{{() AaBbcccCCC ok] @@@12
[this a test file --*{{() AaBbcccCCC ok] @@@13
[this a test file
--*{{() AaBbcccCCC ok] @@@14
[this a test file --*{{() AaBbcccCCC ok] @@@15
[this a test file --*{{() AaBbcccCCC ok] @@@20
[ --*{{() ABCCC ] @@@22
[ --*{{() ] @@@22
[thisatestfile--*{{()AaBbcccCCCok] @@@30