|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-01-15 10:41 UTC] andrei@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 21:00:02 2025 UTC |
$data = "abc\0\0de"; # \0, \x00 - never mind preg_match('/ab(.{4})e/s', $data, $res); echo(bin2hex($data)); # 61626300006465 echo(bin2hex($res[0])); # 616263 echo(bin2hex($res[1])); # 63 PHP4.0.6/Win32 (binary distr.) From PHP PCRE docs: -------------- 4. Though binary zero characters are supported in the subject string, they are not allowed in a pattern string because it is passed as a normal C string, terminated by zero. The escape sequence "\0" can be used in the pattern to represent a binary zero. ----------- From original PCRE docs (http://www.pcre.org/man.txt): -------- The subject string is passed as a pointer in subject, a length in length, and a starting offset in startoffset. Unlike the pattern string, the subject may contain binary zero characters. When the starting offset is zero, the search for a match starts at the beginning of the subject, and this is by far the most common case. --------- by the way, it seems that preg_replace() works correctly. Problems with preg_match() please report if i'm wrong and it isn't a bug.