RE: [PHP] Null character as field seperator in a string.

From: Date: Mon, 29 Apr 2002 13:56:04 +0000
Subject: RE: [PHP] Null character as field seperator in a string.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-95151@lists.php.net to get a copy of this message
> On Monday 29 April 2002 18:26, Dave MacRae wrote: > > For historic reasons, I have a file that contains a number of records in > > which the fields are seperated by the NULL character, i.e, > > > > field1\0field2\0field3\0field4 > > > > I need to parse out the fields from this string. > > > > The string is read into the program using > > > > $buffer = fgets(...). > > > > This would be no problem in Perl or C but I cannot get this to > work in PHP. > > > > I have tried using > > > > preg_split("/\0/", $buffer); > > > > But this fails. I've tried walking through the string but it seems that > > $buffer only has the content up to the first NULL character. > > Try using fread() to get your file (it's binary safe). Then use: > > explode(chr(0), $buffer); > > to separate your fields. I'm beginning to think this may be the only solution. I now have to figure out how to process the records as I'm looking for the data in a particular line in the file, this should be fairly easy. Thanks. Dave

« previous php.general (#95151) next »