首页 > Web开发 > 详细

PHP 正则 空字符 / NUL字符

时间:2018-10-12 12:58:14      阅读:193      评论:0      收藏:0      [点我收藏+]

\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);

 

PHP 正则 空字符 / NUL字符

原文:https://www.cnblogs.com/phpdragon/p/9777312.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!