I’m writing a function intended to sanitize a poorly formatted string which the php script will receive from an outside source. The problem with this string is that every odd numbered byte is zero, so what the function does is that it pushes every even numbered byte to a new array. Code:
$serverInfoClean = array();
for ($i = 0; $i < strlen($serverInfo); $i++ ) // Remove every odd numbered byte
{
if ($i & 1) // Odd index
{
// Do nothing
}
else // Even index
{
array_push($serverInfoClean, $serverInfo[i]);
echo $i . ' ' . $serverInfo[i] . '<br/>'; // Debug
}
}
The debug line is there so I can see in my browser which values it returns. It returns the first character in the string every single time.
1 Answer