Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP's XML Output Error: "XML or text declaration not at the start of entity"
    primarykey
    data
    text
    <p>I'm using PHP version > 5.2 (5.2.17 on my web server and 5.3.6 on my localhost) with the following settings:</p> <pre><code>output_buffering = On output_handler = ob_gzhandler </code></pre> <p>In the following PHP script I'm outputting an XML response to use with jQuery/AJAX</p> <pre><code>if (empty($_GET)) { $Response = new Response('getlanguage'); $Response-&gt;DisplayLanguage(LanguagesManager::GetLanguage()); die(); } IOManager::InputSanitizeRequest($_GET); $Language = isset($_GET['language']) ? $_GET['language'] : ''; $Response = new Response('setlanguage'); if (LanguagesManager::ValidateLanguage($Language)) { LanguagesManager::SetLanguage($Language); $Response-&gt;DisplayResult(true); } else $Response-&gt;DisplayResult(false); </code></pre> <p>But my jQuery/AJAX function is not working and, if I try to manually check the output of my PHP script, I get the following error on Mozilla Firefox:</p> <pre><code>XML Parsing Error: XML or text declaration not at the start of entity Address: http://127.0.0.1/responses/requestlanguage.php?language=it Line Number 1, Column 2: &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; -^ </code></pre> <p>And that's caused by a trailing whitespace before the XML declaration:</p> <pre><code>" &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;" </code></pre> <p>I've checked out my PHP tags and everything is fine. After messing up a little bit with my code, I discoveded something incredible: the whitespace is created by this function:</p> <pre><code>LanguagesManager::ValidateLanguage($Language) public static function ValidateLanguage($Language) { return in_array($Language, self::GetSupportedLanguages()); } </code></pre> <p>If I comment the whole if statement, or if i replace that function with a simple "true" I don't get the parsing error anymore... well, I just can't belive it. Can someone explain me why? Anyone knows a solution?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload