Which piece of code is 'better?' : <p>I have two pieces of code. Can you please tell me which one is correct and more secure?</p>

<pre><code>&lt;input type="text" class="form-control contact__form-control"    placeholder="Your Name *" id="name" value="&lt;?php echo htmlspecialchars ($name); ?&gt;"&gt;
&lt;?php echo "&lt;span class='text-danger'&gt;$nameError&lt;/span&gt;";?&gt;
</code></pre>

<p>or</p>

<pre><code>&lt;input type="text" class="form-control contact__form-control" placeholder="Your Name *" id="name" value="&lt;?php echo htmlspecialchars ($name); ?&gt;"&gt;
&lt;?php echo htmlspecialchars ("&lt;span class='text- danger'&gt;$nameError&lt;/span&gt;");?&gt;
</code></pre>

<p>I have seen everyone to use the 1st one but i read that in PHP when you echo something its good to add htmlspecialchars for security reason. So i am wondering if the second piece of code is correct. Will the bootstrap  alert class will work after the htmlspecialchars</p>
