title: PHP SimpleXML parse differently depending on line break
body: <p>I want to parse XML string using SimpleXML on PHP.</p>
  
  <pre><code>$xml = '&lt;root&gt;&lt;case1&gt;&lt;name&gt; &lt;/name&gt;&lt;/case1&gt;&lt;case2&gt;&lt;name&gt;&lt;/name&gt;&lt;/case2&gt;&lt;case3&gt;&lt;name&gt;ukits&lt;/name&gt;&lt;/case3&gt;&lt;/root&gt;';
  
  libxml_use_internal_errors(true);
  
  $content = simplexml_load_string($xml);
  
  if ($content === false) {
      libxml_clear_errors();
  }
  
  print_r($content);
  
  $content = objectToArray($content);
  
  print_r($content);
  
  function objectToArray($obj) {
      if (is_object($obj)) { $obj = (array) $obj; }
  
      if (count($obj) == 0) { $obj = ''; }
  
      if (is_array($obj)) {
          $new = array();
          foreach ($obj as $key =&gt; $val) {
              $new[$key] = objectToArray($val);
          }
      } else {
          $new = $obj;
      }
      return $new;
  }
  </code></pre>
  
  <p>This code returns:</p>
  
  <pre><code>SimpleXMLElement Object
  (
      [case1] =&gt; SimpleXMLElement Object
          (
              [name] =&gt; SimpleXMLElement Object
                  (
                      [0] =&gt;  
                  )
          )
      [case2] =&gt; SimpleXMLElement Object
          (
              [0] =&gt; SimpleXMLElement Object
                  (
                  )
          )
      [case3] =&gt; SimpleXMLElement Object
          (
              [name] =&gt; ukits
          )
  )
  Array
  (
      [case1] =&gt; Array
          (
              [name] =&gt; Array
                  (
                      [0] =&gt;  
                  )
          )
      [case2] =&gt; Array
          (
              [0] =&gt; 
          )
      [case3] =&gt; Array
          (
              [name] =&gt; ukits
          )
  )
  </code></pre>
  
  <p>There seems to be 2 unexpected problems. In case1, <strong>name tag has a OBJECT child</strong> (not spaced string). In case2, <strong>case2 tag has a numeric array</strong>.</p>
  
  <p>But, if the XML string contains line break or space after 'name' tag, the result is different. like this:</p>
  
  <pre><code>$xml = '&lt;root&gt;&lt;case1&gt;&lt;name&gt; &lt;/name&gt;
  &lt;/case1&gt;&lt;case2&gt;&lt;name&gt;&lt;/name&gt;
  &lt;/case2&gt;&lt;case3&gt;&lt;name&gt;ukits&lt;/name&gt;&lt;/case3&gt;&lt;/root&gt;';
  </code></pre>
  
  <p>The same code returns:</p>
  
  <pre><code>SimpleXMLElement Object
  (
      [case1] =&gt; SimpleXMLElement Object
          (
              [name] =&gt; SimpleXMLElement Object
                  (
                  )
          )
      [case2] =&gt; SimpleXMLElement Object
          (
              [name] =&gt; SimpleXMLElement Object
                  (
                  )
          )
      [case3] =&gt; SimpleXMLElement Object
          (
              [name] =&gt; ukits
          )
  )
  Array
  (
      [case1] =&gt; Array
          (
              [name] =&gt; 
          )
      [case2] =&gt; Array
          (
              [name] =&gt; 
          )
      [case3] =&gt; Array
          (
              [name] =&gt; ukits
          )
  )
  </code></pre>
  
  <p>This result is that I want to get.</p>
  
  <p>The point is WHY the results of "same structured XML strings" are differnt depend on line break.</p>
  
  <p>And how do I do If I want to get what I want like second result?
  (An input string have to contain no line break.)</p>
  
  <p>Here is my configuration:</p>
  
  <pre><code>CentOS 6.7
  PHP 5.4.45
  SimpleXML Revision $Id: 16070fc92ad6f69cebb2d52ad3f02794f833ce39 $
  libxml2 Version 2.7.6
  </code></pre>