title: Variable value inside XML tag
body: <p>I want to put the value of $album into an XML tag called category. But everything I try is wrong. The closest I get is the variable name $album but not the data inside. I'm new to writing XML with php. I have tried all sorts of concatenation &amp; have seen CDATA mentioned here but don't know if I should be using it or how. </p>
  
  <pre><code>&lt;?php
  $dbhost = "localhost";
  $dbuser = "user";
  $dbpass = "password";
  $dbname = "db";
  @mysql_connect($dbhost,$dbuser,$dbpass);
  mysql_select_db($dbname);
  
  
  $sql = "SELECT * FROM responsivegallery_rgal";
  $q   = mysql_query($sql) or die(mysql_error());
  
  $album = $q['album_rgal'];
  $category_tag = '"&lt;category caption = ". $album ."&gt;"';
  
  $xml = "&lt;gallery&gt;";
  while($r = mysql_fetch_array($q)){
  
  
    $xml .= $category_tag ."&lt;/category&gt;";
    $xml .= "&lt;item&gt;"; 
    $xml .= "&lt;image&gt;"."gallery_files/slides/".$r['image_rgal']."&lt;/image&gt;";
    $xml .= "&lt;thumb&gt;"."gallery_files/slides/".$r['thumb_rgal']."&lt;/thumb&gt;";  
    $xml .= "&lt;caption&gt;".$r['title_rgal']."&lt;/caption&gt;";
    $xml .= "&lt;/item&gt;";  
  }
  $xml .= "&lt;/gallery&gt;";
  $sxe = new SimpleXMLElement($xml);
  $sxe-&gt;asXML("test.xml");
  //$sxe-&gt;asXML("../gallery_files/gallery.xml");
  ?&gt;
  </code></pre>