我有这段代码来处理配置文件:
<?php
$config = '[log]
log_writers[] = "file"
log_writers[] = "screen"
[General]
maintenance_mode = 0
enable_browser_archiving_triggering = 0
enable_sql_optimize_queries = 0
force_ssl = 1';
echo preg_match_all( '/^maintenance_mode[ \t]*=[ \t]*\d$/m', $config );
回波显示0
将正则表达式更新为:
echo preg_match_all( '/^maintenance_mode[ \t]*=[ \t]*\d\s$/m', $config );
结果达到预期1
为什么??
我什至在 regex101 中验证了我的理智
https://regex101.com/r/CIxCkN/1
本地测试环境:
RHEL 7
PHP 5.6.25
PCRE v8.32 2012-11-30
和
Windows Server 2022
PHP 8.2.7
PCRE v10.40 2022-04-14
根据评论请求:
var_dump(base64_encode($config));
字符串(240)“W2xvZ10NCmxvZ193cml0ZXJzW10gPSAiZmlsZSINCmxvZ193cml0ZXJzW10gPSAic2NyZWVuIg0KDQpbR2VuZXJhbF0NCm1haW50ZW5hbmNlPSA21vZGUgwDQplbmFibGVfY nJvd3Nlcl9hcmNoaXZpbmdfdHJpZ2dlcmluZyA9IDANCmVuYWJsZV9zcWxfb3B0aW1pemVfcXVlcmllcyA9IDANCmZvcmNlX3NzbCA9IDE="
var_dump(bin2hex($config));
字符串(358)“5b6c6f675d0d0a6c6f675f777269746572735b5d203d202266696c65220d0a6c6f675f777269746572735b5d203d202273637265656e220d0a0 d0a5b47656e6572616c5d0d0a6d61696e74656e616e63655f6d6f6465203d20300d0a656e61626c655f62726f777365725f617263686976696e675f7472 6967676572696e67203d20300d0a656e61626c655f73716c5f6f7074696d697a655f71756572696573203d20300d0a666f7263655f73736c203d2031"