There is a problem: how to replace a specific string in a string. For example, replace abc in the string: abcfdabertDefdaAbcfdd, where abc is case-insensitive. after the replacement, the string is: fdabertDefdafdd, which immediately comes up with two policies: preg_r... "/> <scripttype =" text/javascript
There is a problem: how to replace a specific string in a string. For example, replace abc in the string Abc fdab ertDe fda abc fdd, where abc is case-insensitive and the string after replacement is fdab ertDe fda fdd.
At that time, we immediately thought of two policies: preg_replace regular expression replacement and preg_split split and merge. Alas, but there was no manual at the time, and there was always no courage to try it. show the code here. it seems that you have to pay attention to it in the future. On the code bar:
[Php]
$ Str = 'ABC fdab ertDe fda abc fdd ';
$ Pat = '/abc/I ';
$ Rtn = preg_replace ($ pat, '', $ str,-1 );
Echo 'orig: ', $ str ,'
';
Echo 'dest: ', $ rtn;
$ Str = 'ABC fdab ertDe fda abc fdd ';
$ Pat = '/abc/I ';
$ Rtn = preg_replace ($ pat, '', $ str,-1 );
Echo 'orig: ', $ str ,'
';
Echo 'dest: ', $ rtn; click preg_replace to View function usage. Then showshowpreg_split:
[Php]
$ Str = 'ABC fdab ertDe fda abc fdd ';
$ Pat = '/abc/I ';
$ Arr = preg_split ($ pat, $ str );
$ Rtn = implode ('', $ arr );
Echo 'orig: ', $ str ,'
';
Echo 'dest: ', $ rtn;
$ Str = 'ABC fdab ertDe fda abc fdd ';
$ Pat = '/abc/I ';
$ Arr = preg_split ($ pat, $ str );
$ Rtn = implode ('', $ arr );
Echo 'orig: ', $ str ,'
';
Echo 'dest: ', $ rtn;
Haha, this method is stupid, but it is also a way, but it is still a regular expression in the final analysis. Is there another way? thanks to the manual in hand, there is no way to be stupid:
[Plain]
$ Str = 'ABC fdab ertDe fda abc fdd ';
$ Tran = array ('ABC' => '', 'ABC' => '');
$ Rtn = strtr ($ str, $ tran );
Echo 'orig: ', $ str ,'
';
Echo 'dest: ', $ rtn;
$ Str = 'ABC fdab ertDe fda abc fdd ';
$ Tran = array ('ABC' => '', 'ABC' => '');
$ Rtn = strtr ($ str, $ tran );
Echo 'orig: ', $ str ,'
';
Echo 'dest: ', $ rtn;
This method is tricky. it is not a good method to avoid regular expressions and deviate from others' purposes!
This time, we should reflect on the regular expressions. although I have learned a lot about the regular expressions, I have also written some. You can always read the manual when using it, and rewrite the manual without stopping it. I am afraid of it. I should write more and practice more in the future to become familiar with this basic skill.