title: How to sanitse information in RSS XML
body: <p>I've created an RSS PHP Script which pulls information directly from a database so that I can pull and display the information on a WordPress website. The issue I am having is the XML is showing some errors</p>
  
  <pre><code>error on line xxx at column xxx: xmlParseEntityRef: no name
  </code></pre>
  
  <p>I've tried using sanitisation, and preg/str replace but no luck. PHP 7.3.8 running Linux and MySQL 5 and Apache 2.</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
      // Create connection
      $con = mysqli_connect("ip", "username", "password");
  
      // Check connection
      if (mysqli_connect_errno($con)) {
          echo "Database connection failed!: " . mysqli_connect_error();
      }
  
      $sql = "SELECT * FROM database.table ORDER BY id DESC LIMIT 25";
      $query = mysqli_query($con,$sql);
      header("Content-type: text/xml");
      echo "&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;rss version='2.0'&gt;
  &lt;channel&gt;
  &lt;title&gt;My Title&lt;/title&gt;
  &lt;link&gt;/&lt;/link&gt;
  &lt;description&gt;Description about the RSS Feed.&lt;/description&gt;
  &lt;language&gt;en-us&lt;/language&gt;";
      while($row = mysqli_fetch_array($query)) {
          $rowid = $row['id'];
          $id = $row['buyer_id'];
          $title = $row['title'];
          $message = preg_replace('/&amp;(?!#?[a-z0-9]+;)/', '&amp;amp;', $row['message']);
          $message = str_replace('\'', '"', $message);
          $update = preg_replace('/&amp;(?!#?[a-z0-9]+;)/', '&amp;amp;', $row['update']);
          $update = str_replace('\'', '"', $update);
          $url = $row['url'];
          $created_at = $row['created_at'];
          $updated_at = $row['updated_at'];
          echo "&lt;item&gt;
  &lt;title&gt;$title&lt;/title&gt;
  &lt;link&gt;$url&lt;/link&gt;
  &lt;description&gt;$message&lt;/description&gt;
  &lt;update&gt;$update&lt;/update&gt;
  &lt;pubDate&gt;$created_at&lt;/pubDate&gt;
  &lt;/item&gt;";
      }
      echo "&lt;/channel&gt;
  &lt;/rss&gt;";
  ?&gt;
  </code></pre>
  
  <p>I get this error <a href="https://i.imgur.com/cnQ8pjb.png" rel="nofollow noreferrer">https://i.imgur.com/cnQ8pjb.png</a> which seems to be referencing an &amp; sign which should be getting replaced. <a href="https://i.imgur.com/PBsPjcn.png" rel="nofollow noreferrer">https://i.imgur.com/PBsPjcn.png</a></p>
  
  <p>Please can you assist?</p>