| 1 | <?php\r |
| 2 | \r |
| 3 | $code = "++++++++[>+++++++++<-]>.<+++++[>++++++<-]>-.+++++++..+++.<++++++++[>>++++<<-]>>.<<++++[>------<-]>.<++++[>++++++<-]>.+++.------.--------.>+.";\r |
| 4 | \r |
| 5 | $buffer = "";\r |
| 6 | $pos = 0;\r |
| 7 | $while = array(); // array($i, ...)\r |
| 8 | for ($i=0; $i < strlen($code); $i++) {\r |
| 9 | switch ($code{$i}) {\r |
| 10 | case '>': $pos++; break;\r |
| 11 | case '<': $pos--; break;\r |
| 12 | case '+': $buffer{$pos} = chr(ord($buffer{$pos}) + 1); break;\r |
| 13 | case '-': $buffer{$pos} = chr(ord($buffer{$pos}) - 1); break;\r |
| 14 | case '.': echo $buffer{$pos}; break;\r |
| 15 | case ',': $buffer{$pos} = fgetc(STDIN); break;\r |
| 16 | case '[': if (ord($buffer{$pos})) $while[] = $i; else for ($depth=1; $depth; $i++) {\r |
| 17 | if ($code{$i+1} == '[') $depth++;\r |
| 18 | elseif ($code{$i+1} == ']') $depth--;\r |
| 19 | }\r |
| 20 | break;\r |
| 21 | case ']': $i = array_pop($while) - 1; break;\r |
| 22 | default: echo "Unrecognized character.\n"; exit(1);\r |
| 23 | }\r |
| 24 | }\r |
| 25 | \r |
| 26 | echo("\n\n");\r |
| 27 | \r |
| 28 | ?>\r |