I have a question about this situation, How could I store string via Array?
this is my code
<?php
$octets = array($_POST["oct1"],$_POST["oct2"],$_POST["oct3"],$_POST["oct4"]);
$octlenfnl = count($octets) - 1;
$binoctstr = 0 ;
if($_POST["oct1"] <= 255 && $_POST["oct1"] <= 255 && $_POST["oct1"] <= 255 && $_POST["oct1"] <= 255)
{
for($i=0;$i<=$octlenfnl;$i++){
echo str_pad(decbin($octets[$i]), 8, '0', STR_PAD_LEFT) , " ";
}
}
else
{
echo "Invalid IP!";
}
?>
It outputs entered IP to Binary octets just like this 11111111 0001000 10010101 10010101, they have spaces between the Octets, how can I split them and store it to array that is accessible globally?
Thanks
isntead of echoing out your results store them into an array something like this
UPDATE EDIT FOR SIMPLIFIED CODE
You can potentially simplfy the code a little I think like this save you creating a second array and just manipulating your existing array. Unless you need that initial array for anything this should work fine