Reply to Re: preg_match - how to match \x00 (null)?

Your name:

Reply:


Posted by Chung Leong on 06/06/06 21:23

Yandos wrote:
> Hi all,
>
> I'd like to work with a binary file....
>
> I read the whole file into variable (it conatains binary data from 00-FF):
>
> $fp=fopen($cfg,"r");
> $content=fread($fp,filesize($cfg));
> fclose($fp);
>
> // and then I'd like to check if it contains special binary sequence, let's say bytes "00 01
> 02 03":
>
> $replacestring="/\x00\x01\x02\x03/im";
>
> if (preg_match($replacestring,$content)==0) {
> echo("bad input file format");
> exit();
> }
>
> but i get error message:
>
> <b>Warning</b>: preg_match(): No ending delimiter '/' found in <b>test.bat</b> on
> line <b>57</b><br />
>
> I think it is maybe because php uses strings terminated with null, but can i force php to
> use strings with predefined length for example? Is there a way to work with strings
> containing null characters?
>
> Thank you in advance.
>
> Y.

The PCRE library does expect the pattern to be a null-terminate string.
It is capable of looking for \0 though. Instead of the double-quoted
string, use single-quotes instead:

$replacestring='/\x00\x01\x02\x03/im';

Now PCRE will see the escape sequences and correctly compile the regexp.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация