1

i have a form on a PHP page. All i trying to do is parse out some XML entered into that form (COMMAND) using simplexml_load_string here is the test code:

<?php
    if($_POST){
        $Input = $_GET['COMMAND'];
        $Data =<<<XML
        <?xml version="1.0" encoding="ISO-8859-1"?> .
        $Input .XML;

        $xml = simplexml_load_string($Data);
        var_dump($xml); 
    }
        else
    }
        echo 'WTF!'
    }
?>

  <form id="form1" name="form1" method="post" action="index.php">
    <textarea name="COMMAND" id="COMMAND" cols="45" rows="5">
        <API>
         <COMMAND>Test</COMMAND>
        </API>
   </textarea>
   <input type="submit" name="button" id="button" value="Submit" />
  </form>

this is the error i am receiving:

Parse error: syntax error, unexpected $end in /var/www/cgi/index.php on line 24

i think it has something to do with my weak attempt at concatenation.

hakre
  • 193,403
  • 52
  • 435
  • 836
  • thanks dave, i did fix that but it still didn't rid me of the error. –  Jul 21 '09 at 20:06
  • [Reference - What does this error mean in PHP?](http://stackoverflow.com/q/12769982/367456) – hakre Dec 15 '12 at 19:50

2 Answers2

2

You have a closing brace where you want an opening brace:

}
    else
}   // <- BAD!
    echo 'WTF!'
}

You want:

}
    else
{   // <- GOOD!
    echo 'WTF!'
}

This is a personal choice, but I'd recommend following the PEAR standard for PHP coding. Your code would appear as:

if (...) {
} else {
}

Makes it a lot easier to catch those evil braces!

hobodave
  • 28,925
  • 4
  • 72
  • 77
0

In addition to what hobodave wrote you are missing a ; on your

echo 'WTF!';

line

Rob Booth
  • 1,792
  • 1
  • 11
  • 22
  • You'll need to supply more code then if you want better debugging. From what you showed us hobodave and I have pointed out the syntax errors. But we don't know if you have a problem in another place. Other than the syntax errors we've pointed out your supplied code looks good. – Rob Booth Jul 30 '09 at 21:21