title: Using preg_replace to replace string inside
body: <pre><code>&lt;?php
  
  $str = htmlspecialchars('&lt;nav&gt;&lt;a&gt;something&lt;/a&gt;&lt;/nav&gt;');
  
  $pattern = htmlspecialchars('/&lt;nav&gt;&lt;a&gt;something&lt;/a&gt;&lt;/nav&gt;/i');
  
  echo htmlspecialchars(preg_replace($pattern, '&lt;nav&gt; &lt;a href=&quot;hi&quot;&gt;click&lt;/a&gt; 
  
  &lt;/nav&gt;', $str));
  
  ?&gt;
  </code></pre>
  <p>I need PHP to <code>echo</code> like this:</p>
  <pre><code>&lt;nav&gt; &lt;a href=&quot;hi&quot;&gt;click&lt;/a&gt; &lt;/nav&gt;
  </code></pre>
  <p>But it's showing this error:</p>
  <blockquote>
  <p>Warning: preg_replace() expects parameter 4 to be int, string given in
  /opt/lampp/htdocs/Workaera/Sample.php on line 19</p>
  </blockquote>