title: PHP DOM createElement - allow spaces
body: <p>How to use spaces in createElement while creating xml file</p>
  
  <p>I have to use </p>
  
  <pre><code>$main = $doc-&gt;createElement("$cname"."Data" );
  </code></pre>
  
  <p>where </p>
  
  <pre><code>$cname="Company Name"
  </code></pre>
  
  <p>But due to spaces in <code>$cname</code>, I am getting the following error,</p>
  
  <blockquote>
    <p>Fatal error: Uncaught exception
    'DOMException' with message 'Invalid
    Character Error' in file.php:50 Stack
    trace: #0 file.php(50):
    DOMDocument->createElement('geosoft
    company...') #1 {main} thrown in
    file.php on line 50</p>
  </blockquote>
  
  <p>How to rectify this?</p>
  
  <p>Regards,
  Rekha</p>