Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP explode on null character

Tags:

php

hex

explode

I am trying to explode a string on what looks like to be a null character.

This is what is what I am using: $exp = explode('\x00', $bin);.

Though this does not work. However, if I do $exp = explode($bin[5], $bin); (where character 5 of $bin is this character I want to explode on) it works fine.

If I do var_dump($bin[5]) It shows me square block with a question mark in it (), and in the view source I get: �

Can anyone tell me what the best way would be to explode on this character? or even if it is the null character (which according to ascii tables it is, unless I am reading it all wrong).

Thanks

like image 668
Hosh Sadiq Avatar asked Mar 22 '11 09:03

Hosh Sadiq


1 Answers

Try double quotes:

$exp = explode("\x00", $bin);

Alternatively, capture the equivalent ASCII character code and pass it using chr.

$char = ord($bin[5]);

// Replace this with the actual number returned from ord
$exp = explode(chr($char), $bin);

This latter example eliminates the possibility that it might not actually be a null character if you haven't already determined it.

like image 50
Michael McTiernan Avatar answered Sep 29 '22 20:09

Michael McTiernan