The matches in () will be put into the array. The question is what is the difference between $1 and \\1?
争渡
争渡 2017-11-30 14:07:51
0
2
1697

ubb text editing, preg_replace($pattern,$replace,$stirng);

争渡
争渡

reply all(1)
 

I read in the manual that \\1 and $1 are the same.

Original words from the manual: Replacement can contain back references \\n or $n, and the latter is preferred grammatically. Each such reference will be replaced by the text captured by the matching nth capturing subgroup. n can be 0-99, \\0 and $0 represent the complete pattern matching text. The serial number counting method of capturing subgroups is: the left bracket representing the capturing subgroup is counted from left to right, starting from 1. If you want to use backslashes in replacement, you must use 4 ("\\\\", translator's annotation: Because this is first a PHP string, after escaping, there are two, and then after passing through the regular expression engine is considered a text backslash).

  • reply If we talk about the difference, it is: preg_replace() We don’t know whether we want to express \\11 or \\1 1 (the second 1 is the string 1). So using ${1}1 can let preg_replace() know that the first 1 is a backreference, and the second 1 is just the 1 of the original text immediately following the backreference.
      author 2018-01-29 16:00:36
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!