PHP simplexml_load_string include form field data

PHPsimplexml

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.

Best Answer

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!