Home  >  Article  >  Backend Development  >  php 正则表达式匹配{"x47x4cx4fx42x41Lx53"}

php 正则表达式匹配{"x47x4cx4fx42x41Lx53"}

WBOY
WBOYOriginal
2016-06-06 20:23:281495browse

怎么匹配出来\x47 \x4c 这些ascii字符?
我用preg_match_all('/\\x(.{2})/i', $str, $matches)匹配的就是出不来,哪里写错了?

回复内容:

怎么匹配出来\x47 \x4c 这些ascii字符?
我用preg_match_all('/\\x(.{2})/i', $str, $matches)匹配的就是出不来,哪里写错了?

对于 $str = "\x47\x4c\x4f\x42\x41L\x53" 也就是 $str = "GLOBALS" 的情况,\x47 是一个字符,不能用 \x.. 匹配,而只能匹配一个范围,例如 [\x00-\xFF]
对于 $str = "\\x47\\x4c\\x4f\\x42\\x41L\\x53" 的情况,上面的代码差不多能用,但应该采用 \\\\ 匹配一个反斜杆,先经过字符串转义,再经过正则转义。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn