It was defeated by PHP regular expressions... I simply matched four consecutive numbers such as abba & nbsp; and used subexpressions and reverse references in them. The results were not captured. I really don't know why, where did I write wrong? & Lt ;? Phpheader ("Content-type: text/html; charset = utf-8"); $ str = "fdsafsdaf is defeated by PHP regular expressions...
I simply matched four consecutive numbers such as abba, and used subexpressions and reverse references. The results were not captured. I really don't know why. Where did I write wrong?
Header ("Content-type: text/html; charset = utf-8 ");
$ Str = "fdsafsdafsgfdag1223fa1551sdfassd3265 ";
$ Mypreg = "/(\ d) \ 2 \ 1/"; // a number that matches the abba type, that is, the above 1551
$ Mycon = "this is a number ";
$ Str = preg_replace ($ mypreg, $ mycon, $ str );
Echo $ str ."
";
Share:
------ Solution --------------------
Well, it's about double quotation marks.
The escape character of double quotation marks takes effect.
$a = "/(\d)(\d)\2\1/";
$b = '/(\d)(\d)\2\1/';
var_dump($a == $b);
var_dump($a, $b);
Bool (false) string (12) "/(\ d)/" string (14) "/(\ d) \ 2 \ 1 /"
To do this
$a = "/(\d)(\d)\\2\\1/";
$b = '/(\d)(\d)\2\1/';
var_dump($a == $b);
var_dump($a, $b);
Bool (true) string (14) "/(\ d) \ 2 \ 1/" string (14) "/(\ d) \ 2 \ 1 /"
So you will see a series \
\\\,\\\\....
Add
------ Solution --------------------
Reference:
I simply matched four consecutive numbers such as abba, and used subexpressions and reverse references. The results were not captured. I really don't know why. Where did I write wrong?
Header ("Content-type: text/html; charset = utf-8 ");
$ Str = "fdsafsdafsgfdag1223fa1551sdfassd3265 ";
$ Mypreg = "/(\ d) \ 2 \ 1/"; // a number that matches the abba type, that is, the above 1551
$ Mycon = "this is a number ";
$ Str = preg_replace ($ mypreg, $ mycon, $ str );
Echo $ str ."
";
We recommend that you use single quotes for regular expressions in PHP, that is:
$ Str = "fasdgasgdfgduuuuu1221uuuufasdfsdfsdaf4444 ";
$ Mypreg = '/(\ d) \ 1 {3}/I ';
$ Mycon = "this is a number ";
Echo $ str ."
";
$ Str = preg_replace ($ mypreg, $ mycon, $ str );
Echo $ str ."
";
Because PHP \ will escape in double quotation marks