Task: Execute Brain____

C: #include <stdio.h>
int main(){
     int ptr=0, i=0, cell[7];
     for( i=0; i<7; ++i) cell[i]=0;
     ptr+= 1;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 8;
     while(cell[ptr])
     {
          ptr-= 1;
          if(ptr<0) perror("Program pointer underflow");
          cell[ptr]+= 9;
          ptr+= 1;
          if(ptr>=7) perror("Program pointer overflow");
          cell[ptr]-= 1;
     }
     ptr-= 1;
     if(ptr<0) perror("Program pointer underflow");
     putchar(cell[ptr]);
     ptr+= 2;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 1;
     ptr+= 1;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 1;
     ptr+= 1;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 2;
     ptr+= 1;
     if(ptr>=7) perror("Program pointer overflow");
     while(cell[ptr])
     {
          cell[ptr]-= 1;
     }
     cell[ptr]+= 1;
     ptr-= 1;
     if(ptr<0) perror("Program pointer underflow");
     while(cell[ptr])
     {
          ptr+= 1;
          if(ptr>=7) perror("Program pointer overflow");
          while(cell[ptr])
          {
               cell[ptr]-= 1;
               ptr+= 1;
               if(ptr>=7) perror("Program pointer overflow");
               cell[ptr]+= 1;
               ptr-= 2;
               if(ptr<0) perror("Program pointer underflow");
               cell[ptr]+= 4;
               ptr+= 1;
               if(ptr>=7) perror("Program pointer overflow");
          }
          ptr-= 2;
          if(ptr<0) perror("Program pointer underflow");
     }
     ptr+= 1;
     if(ptr>=7) perror("Program pointer overflow");
     putchar(cell[ptr]);
     cell[ptr]+= 7;
     putchar(cell[ptr]);
     putchar(cell[ptr]);
     cell[ptr]+= 3;
     putchar(cell[ptr]);
     ptr+= 2;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 7;
     putchar(cell[ptr]);
     ptr-= 3;
     if(ptr<0) perror("Program pointer underflow");
     while(cell[ptr])
     {
          while(cell[ptr])
          {
               cell[ptr]-= 1;
          }
          ptr-= 1;
          if(ptr<0) perror("Program pointer underflow");
          while(cell[ptr])
          {
               cell[ptr]-= 1;
          }
          ptr+= 1;
          if(ptr>=7) perror("Program pointer overflow");
     }
     ptr-= 1;
     if(ptr<0) perror("Program pointer underflow");
     cell[ptr]+= 15;
     putchar(cell[ptr]);
     ptr+= 2;
     if(ptr>=7) perror("Program pointer overflow");
     putchar(cell[ptr]);
     cell[ptr]+= 3;
     putchar(cell[ptr]);
     cell[ptr]-= 6;
     putchar(cell[ptr]);
     cell[ptr]-= 8;
     putchar(cell[ptr]);
     ptr+= 2;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 1;
     putchar(cell[ptr]);
     ptr+= 1;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 4;
     putchar(cell[ptr]);
     return 0;
}






PHP: <?php
function brainfuck_interpret(&$s, &$_s, &$d, &$_d, &$i, &$_i, &$o) {
   do {
     switch($s[$_s]) {
       case '+': $d[$_d] = chr(ord($d[$_d]) + 1); break;
       case '-': $d[$_d] = chr(ord($d[$_d]) - 1); break;
       case '>': $_d++; if(!isset($d[$_d])) $d[$_d] = chr(0); break;
       case '<': $_d--; break;
       case '.': $o .= $d[$_d]; break;
       case ',': $d[$_d] = $_i==strlen($i) ? chr(0) : $i[$_i++]; break;
       case '[':
         if((int)ord($d[$_d]) == 0) {
           $brackets = 1;
           while($brackets && $_s++ < strlen($s)) {
             if($s[$_s] == '[')
               $brackets++;
             else if($s[$_s] == ']')
               $brackets--;
           }
         }
         else {
             $pos = $_s++-1;
           if(brainfuck_interpret($s, $_s, $d, $_d, $i, $_i, $o))
             $_s = $pos;
         }
         break;
       case ']': return ((int)ord($d[$_d]) != 0);
    }
  } while(++$_s < strlen($s));
}

function brainfuck($source, $input='') {
  $data         = array();
  $data[0]      = chr(0);
  $data_index   = 0;
  $source_index = 0;
  $input_index  = 0;
  $output       = '';
  
  brainfuck_interpret($source, $source_index,
                      $data,   $data_index,
                      $input,  $input_index,
                      $output);
  return $output;
}

$code = "
    >++++++++[<+++++++++>-]<.>>+>+>++>[-]+<[>[->+<<++++>]<<]>.+++++++..+++.>
    >+++++++.<<<[[-]<[-]>]<+++++++++++++++.>>.+++.------.--------.>>+.>++++.
";
$inp = '123';
print brainfuck( $code, $inp );