[英]PHP regular expression help
I'm working on fixing a few bugs / adding features to a site somebody else built. 我正在修复一些错误/正在向其他人建立的网站添加功能。 Can anyone tell me what the following regexes do?
谁能告诉我以下正则表达式的作用? I'm semi familiar with regular expressions, but I haven't the foggiest idea what these are trying to accomplish.
我对正则表达式有点半熟,但是我还不清楚这些正试图实现什么。
$qsReplace = preg_replace('/\\\t/', "\t", $qsReplace);
$qsReplace = preg_replace('/\\\/', '\\\\\\', $qsReplace);
$qsReplace = preg_replace('/\$([0-9])/','\$````~~~~$1', $qsReplace);
$queryString = preg_replace('/\$\`\`\`\`\~\~\~\~([0-9])/','\$$1', $queryString);
I suspect that whoever coded this was a little bit strange, but I'm not sure. 我怀疑是谁编码的,这有点奇怪,但我不确定。
The third one finds a dollar sign followed by a digit and inserts four backticks and four tildes between the number and the dollar sign. 第三个找到一个美元符号,后跟一个数字,并在数字和美元符号之间插入四个反引号和四个波浪号。 The fourth one removes these backticks and tildes between a dollar and the number.
第四个删除美元和数字之间的这些反引号和波浪号。
I would suspect some more data juggling going on between the two and a hope that no input ever would contain four backticks followed by four tildes... 我怀疑这两者之间还会进行更多的数据处理,并希望没有输入会包含四个反引号,然后是四个波浪号...
(3 & 4 thanks to chx) (感谢chx的3&4)
Converts \\t
into and actual tab 将
\\t
转换成实际的制表符
$qsReplace = preg_replace('/\\\\\\t/', "\\t", $qsReplace);
Escapes Double backslashes, Can be replaced with addslhases();
Escapes双反斜杠,可以用
addslhases();
代替addslhases();
$qsReplace = preg_replace('/\\\\\\/', '\\\\\\\\\\\\', $qsReplace);
Finds a $
followed by a digit such as $01
and replaces with backtick
x4 + ~
x4 (pre) 找到一个
$
后跟数字如$01
,并用替换backtick
X4 + ~
X4(预)
$qsReplace = preg_replace('/\\$([0-9])/','\\$````~~~~$1', $qsReplace);
Removes the $
, backtick
, ~
删除
$
, backtick
, ~
$queryString = preg_replace('/\\$\\`\\`\\`\\`\\~\\~\\~\\~([0-9])/','\\$$1', $queryString);
Obviously the last programmer did not understand a few things. 显然,最后一个程序员不了解一些事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.