0

I have a local XAMPP installation for testing and an webserver for live testing. At my local environment, everything works well. But when I load it up to my server, it gives me the error:

Parse error: syntax error, unexpected '[' in /data/web/e36087/html/pdf/index.php on line 11

But everything seems correct. What can I do?

PHP-Code:

<?php

    setlocale(LC_TIME, 'de_DE.UTF-8');

    $xmldb = "db.xml";

    $xml = simplexml_load_file($xmldb);

    if(isset($_POST["remove"])) {

        unlink($xml->xpath('/data//count['.$_POST["remove"].']/fulldir')[0][0]);

        unlink($xml->xpath('/data//count['.$_POST["remove"].']/pdfdir')[0][0].$xml-       >xpath('/data//count['.$_POST["remove"].']/filename')[0][0]);

        $query = $xml->xpath('/data//count['.$_POST["remove"].']')[0][0];

        unset($query[0][0]);
        //Datei schreiben

        $fopen = fopen($xmldb, "w"); 
        fwrite($fopen, $xml->asXML());
        fclose($fopen);

    }

?>

Link to my Webhost: http://livetest.philipgraf.at/

DevTec
  • 307
  • 3
  • 14
  • What's your php version? (local and webhost)? – smarber Dec 23 '14 at 13:12
  • It's part of the [PHP error reference](http://stackoverflow.com/q/12769982/367456) on site: [Parse error: syntax error, unexpected '['](http://stackoverflow.com/a/22316776/367456) - please use the search before posting a question. – hakre Dec 23 '14 at 13:17
  • Oh, excuse me! Altough I searched before I didn't find the Question. I didn't even know that this reference exists! – DevTec Dec 23 '14 at 13:20

1 Answers1

4

Function array dereferencing was first added in PHP 5.4. It's likely that your host is running 5.3.

In short this means that

unlink( $xml->xpath('/data//count['.$_POST["remove"].']/fulldir')[0][0] );

must be written as this:

$path = $xml->xpath('/data//count['.$_POST["remove"].']/fulldir');
unlink( $path[0][0] );

So essentially, save your method result to a variable before using indexes.

h2ooooooo
  • 39,111
  • 8
  • 68
  • 102
  • Thanks for your answer! At my webhost I'm using PHP 5.3 and at local 5.4. I'll accept your answer in ten minutes. – DevTec Dec 23 '14 at 13:16