title: grab info from a form and append it in an xml file directly using php with closing tags '< >' entact
body: <p>I am new to php.This post might look lengthy but its nothing but a simple project .Here i am trying to get info from a from and fill an xml file with it .But to do so i must elements name closed with <code>&lt;&gt;</code> tags.I have used <code>&amp;lt</code> and <code>&amp;gt</code> entities in my php file.It gives desired output when i echo output on the browsers </p>
  
  <p>output on firefox browser  <strong>I WANT SIMELAR OUTPUT FOR MY XML FILE:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/nGpRH.png" alt="enter image description here"></p>
  
  <p>but when i write to a xml file  the closing tags disappeared and &amp;lt and &amp;gt return back and the xml file looks messy,actually it doesn't look like an xml file at all.</p>
  
  <p>Here is how it looks like in my xml file:</p>
  
  <p><img src="https://i.stack.imgur.com/iPCSz.png" alt="enter image description here"></p>
  
  <p>How i can solve this problem?</p>
  
  <p><strong>Form:</strong></p>
  
  <pre><code>&lt;form action="&lt;?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?&gt;" method='POST'&gt;
      &lt;fieldset style='padding-left:30px;width:300px;position:absolute;left:200px;background:lightblue;'&gt;
      &lt;legend style='font-size:20px;'&gt;User Info&lt;/legend&gt;
      Name:&lt;/br&gt;
      &lt;input type='text' placeholder='name' name='name' required&gt;&lt;/br&gt;&lt;/br&gt;
      Email:&lt;/br&gt;
      &lt;input type='email' placeholder='email' name='email'&gt;&lt;/br&gt;&lt;/br&gt;
      Gender :&lt;/br&gt;
      &lt;input type='radio' name='gender' id='male' value='male'&gt;&lt;label for='male'&gt;male&lt;/label&gt;&lt;/br&gt;
      &lt;input type='radio' name='gender' id='female' value='female'&gt;&lt;label for='female'&gt;female&lt;/label&gt;&lt;/br&gt;&lt;/br&gt;
      Select fruit:&lt;/br&gt;
      &lt;select name='opts[]' size='4' style='width:160px;' multiple&gt;
          &lt;option value='apple'&gt;apple&lt;/option&gt;
          &lt;option value='orange'&gt;orange&lt;/option&gt;
          &lt;option value='pineapple'&gt;pineapple&lt;/option&gt;
          &lt;option value='banana'&gt;banana&lt;/option&gt;
          &lt;option value='lichi'&gt;liche&lt;/option&gt;
          &lt;option value='jackfruit'&gt;jackfruit&lt;/option&gt;
          &lt;option value='mango'&gt;mango&lt;/option&gt;
      &lt;/select&gt;
      &lt;/br&gt;&lt;/br&gt;&lt;hr&gt;
      &lt;input type='submit' value='submit'&gt;
      &lt;/fieldset&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>php code</strong></p>
  
  <pre><code>if(isset($_POST['name']) &amp;&amp; isset($_POST['email']) &amp;&amp; isset($_POST['gender']) &amp;&amp; isset($_POST['opts'])){
          if(!empty($_POST['name']) &amp;&amp; !empty($_POST['email']) &amp;&amp; !empty($_POST['gender']) &amp;&amp; !empty($_POST['opts'])){
  
              $name=$_POST['name'];
              $email=$_POST['email'];
              $gender=$_POST['gender'];
              $fruits=$_POST['opts'];
              $fruitsample='';
              foreach($fruits as $elem){
                  $fruitsample .='&amp;ltfruit&amp;gt'.$elem.'&amp;lt/fruit&amp;gt&lt;/br&gt;';
              }
              $fav_fruits='&amp;ltfavFruits&amp;gt&lt;/br&gt;'. $fruitsample.'&amp;lt/favFruits&amp;gt';
              $user='&amp;ltname&amp;gt'.$name.'&amp;lt/name&amp;gt';
              $mail='&amp;ltemail&amp;gt'.$email.'&amp;lt/email&amp;gt';
              $gend='&amp;ltgender&amp;gt'.$gender.'&amp;lt/gender&amp;gt';
              $final='&amp;ltuser&amp;gt&lt;/br&gt;'.$user.'&lt;/br&gt;'.$mail.'&lt;/br&gt;'.$gend.'&lt;/br&gt;'.$fav_fruits.'&lt;/br&gt;&amp;lt/user&amp;gt&lt;/br&gt;';
              echo $final;
  
              $filename='textIt.txt';
              $file=fopen($filename,'a');
              fwrite($file,$final);
  
  
          }else{
              echo 'you have ot select every field';
          }
  
  }
  </code></pre>