title: How do I add line breaks after each tag in the xml
body: <p>I'm working on my php script to generating XML to save the XML file in my web host. I want to make some lines breaks. I need to add line breaks for each tags after the <code>&lt;/channel&gt;</code>, but it will not break for each line in the xml.</p>
  
  <p>Here's the xml output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;tv generator-info-name="www.mysite.com/xmltv"&gt;
  &lt;channel id="ABC FAMILY"&gt;
     &lt;display-name&gt;ABC FAMILY&lt;/display-name&gt;
     &lt;programme channel="ABC FAMILY" start="s1" stop="e1"&gt;
         &lt;title lang="en"&gt;program title&lt;/title&gt;
         &lt;sub-title lang="en"&gt;sub title&lt;/sub-title&gt;
         &lt;desc lang="en"&gt;program description1&lt;/desc&gt;
         &lt;category lang="en"&gt;some category&lt;/category&gt;
     &lt;/programme&gt;
  &lt;/channel&gt; 
  \n
  
  &lt;channel id="CBS"&gt;
     &lt;display-name&gt;CBS&lt;/display-name&gt;
     &lt;programme channel="CBS" start="s1" stop="e1"&gt;
         &lt;title lang="en"&gt;program title&lt;/title&gt;
         &lt;sub-title lang="en"&gt;sub title&lt;/sub-title&gt;
         &lt;desc lang="en"&gt;program description1&lt;/desc&gt;
         &lt;category lang="en"&gt;some category&lt;/category&gt;
     &lt;/programme&gt;
  &lt;/channel&gt; 
  \n
  
  
  
  
  
  &lt;?php
  
  function db_connect()
  {
    define('DB_HOST', 'localhost');
    define('DB_USER', 'myusername');
    define('DB_PASSWORD', 'mypassword');
    define('DB_DATABASE', 'mydbname');
  
    $errmsg_arr = array();
    $errflag = false;
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  
    if(!$link) 
    {
      die('Failed to connect to server: ' . mysql_error());
    }
  
    $db = mysql_select_db(DB_DATABASE);
    if(!$db) 
    {
      die("Unable to select database");
    }
  }
  db_connect();
  
    function clean($var)
    {
      return mysql_real_escape_string(strip_tags($var));
    } 
    $channels = clean($_GET['channels']);
    $id = clean($_GET['id']);
  
    if($errflag) 
    {
      $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
      echo implode('&lt;br /&gt;',$errmsg_arr);
    }
    else 
    {
      $insert = array();
  
      if(isset($_GET['channels'])) 
      {
        $insert[] = 'channels = \'' . clean($_GET['channels']) .'\'';
      }
      if(isset($_GET['id'])) 
      {
        $insert[] = 'id = \'' . clean($_GET['id']) . '\'';
      }
  
      if(!$channels &amp;&amp; ! $id) 
      {
        $qrytable1="SELECT id, channels, links, streams FROM tvguide";
        $result1=mysql_query($qrytable1) or die('Error:&lt;br /&gt;' . $qry . '&lt;br /&gt;' . mysql_error());
  
  
        while ($row = mysql_fetch_array($result1))
        {
          // fake some example data. the actual data would be retrieved from a database query
          $data[] = array('channel_id'=&gt;$row['channels'],
          'display_name'=&gt;$row['channels'],
          'program_id'=&gt;123,'start'=&gt;'s1','stop'=&gt;'e1',
          'title'=&gt;'program title',
           'sub_title'=&gt;'sub title',
           'description'=&gt;'program description1',
           'category'=&gt;'some category');
  
  
  
          // build the xml    
          $xml = '&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;tv generator-info-name="www.mysite.com/xmltv"&gt;';
          $last_channel = null; // used to detect when the channel changes
          foreach($data as $arr)
          {
              if($last_channel != $arr['channel_id'])
              {
                  // the channel changed
                  if($last_channel != null){
                      // not the first channel, close out the previous channel
                      $xml .= '
  &lt;/channel&gt; \n
  ';
                  }
                  // start a new channel
                  $xml .= "
  &lt;channel id=\"{$arr['channel_id']}\"&gt;";
                  $xml .= "
     &lt;display-name&gt;{$arr['display_name']}&lt;/display-name&gt;";
                  $last_channel = $arr['channel_id'];
              }
              // output the program info under each channel
              $xml .= "
     &lt;programme channel=\"{$arr['channel_id']}\" start=\"{$arr['start']}\" stop=\"{$arr['stop']}\"&gt;";
              // i don't see a program id in this definition, but it likely needs one
              $xml .= "
         &lt;title lang=\"en\"&gt;{$arr['title']}&lt;/title&gt;";
              $xml .= "
         &lt;sub-title lang=\"en\"&gt;{$arr['sub_title']}&lt;/sub-title&gt;";
              $xml .= "
         &lt;desc lang=\"en\"&gt;{$arr['description']}&lt;/desc&gt;";
              $xml .= "
         &lt;category lang=\"en\"&gt;{$arr['category']}&lt;/category&gt;";
              $xml .= "
     &lt;/programme&gt;";
          }
          if($last_channel != null)
          {
              // close out the previous channel if any
              $xml .= '
  &lt;/channel&gt;';
          }
       }
  
     }
     $xml .= '
  &lt;/tv&gt;';
     // output the xml to the browser in this example, write $xml to a file here...
     header("Content-Type: text/xml");
     echo $xml;
     $handle = fopen("myChannel.xml", "w"); 
     fwrite ($handle, $xml);
   }
  ?&gt;
  </code></pre>
  
  <p>Can you please tell me how I can break for each line after the <code>&lt;/channel&gt;</code> tag?</p>