PHP 正则 空字符 / NUL字符

\xnn 匹配中ASCII代码十六进制代码为nn的字符。
[\x00-\x7F] 匹配ASCII值从0-127的字符。
0-127表示单字节字符,也就是:数字,英文字符,半角符号,以及某些控制字符。

 

正则示例:

<?php

$test_str = 'a'.chr(0).'bcdefj'.chr(0).'h';

//ASCII码中十进制 0 对应 十六进制 00
$hex_str = '\x00';

$pattern =  sprintf('/a%s[0-9a-zA-Z]{6}%sh/',$hex_str,$hex_str);

preg_match_all($pattern,$test_str,$output); 
var_dump($output);


$test_str = 'a'.chr(31).'bcdefj'.chr(31).'h';

//ASCII码中十进制 31 对应 十六进制 1F
$hex_str = '\x1F';

$pattern =  sprintf('/a%s[0-9a-zA-Z]{6}%sh/',$hex_str,$hex_str);

preg_match_all($pattern,$test_str,$output); 
var_dump($output);

 

posted @ 2018-10-12 11:46  phpdragon  阅读(1696)  评论(0编辑  收藏  举报