This was difficult to put into a title.
Essentially what I want to do is, when I get some random binary code i need certain number patterns be converted into a declared symbol.
For example :
input: 11100011111
Output: ABF
So essentially
- 111 = A, 000 = B,
11111 = C, 1111 = D
Note!That the output has to correspond in order so if it started with 111 the output hast to start with A(declared symbol for said pattern). There's a D there also essentially the first four characters of C is the same as D but it must output the one most similar.
First i tried to put this into a for
loop
so, check string characters, if there's a 1 echo one and vice versa
for ($i=0; $i < $getInput[$i] ; $i++) {
if ($getInput[$i] == 1) {
echo "ONE";
} elseif ($getInput[$i] == 0) {
echo "ZERO";
}
}
this was just for testing, essentially in this theory i can check if if there is a consecutive pattern so 000 it will refer to an array with different patterns already assigned and then output the symbol whatever was assigned to that pattern.
I also tried using foreaches but due to inexperience...
I did some research and found this topic: How do I check if a string contains a specific word?
which kinda helped since with this code
$a = '1110001111';
if (strpos($a, '1111') !== false) {
echo 'D';
}
It outputs the character in right order, problem with this approach is that well it kinda means id need to write out if statements repetitively, and secondly if there were to be 1111 in the input, it would take the part 111 and 1111 as two different strings and output both of them
EDIT:
Essentially what i just thought is, i actually need to compare 4 digits to different patterns, i can put the string into an array split it into 4's and then compare with another array which holds the declared patterns (1111 = a etc..), so in a 4 digit binary 0000 there can be about 17 different patterns therefor no need for anything above >4
Then again if there were an odd number of 1's and 0's there'd be some left off. Then these should just be outputted as is. so if there were 1010110 = A110 since A is declared as a pattern of 1010