The strtok will do this in one pass instead of two:
$hashsalt8 = strtok($hashsalt8, "\0");
Since PHP 4.1.0, however, strtok will not return an empty string if the input string starts with a zero byte. To handle this case, you can do the following:
if ($ hashsalt8 [0] == "\ 0") {
$ hashsalt8 = '';
}
else {
$ hashsalt8 = strtok ($ hashsalt8, "\ 0");
}
Note that an input line starting with a zero byte also throws an error in your current code. In this case, strpos will return 0 and if ($iv) will fail.
You must use the !== operator to distinguish between 0 and false :
$ iv = strpos ($ hashsalt8, "\ 0");
if ($ iv! == false) {
$ hashsalt8 = substr ($ hashsalt8, 0, $ iv);
}
source share