title: How to write PHP variable as HTML attribute value?
body: <p>I am confused about how PHP variable should be written inside an HTML attribute.
  In case of HTML form, we write it as</p>
  
  <pre><code>&lt;form method="POST" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt;
  </code></pre>
  
  <p>Here we echo the PHP variable $_SERVER['PHP_SELF'] inside action attribute.</p>
  
  <p>But in my case when I try to get the server name inside img element src attribute then I get the following error</p>
  
  <pre><code>&lt;img src="&lt;?php echo $_SERVER['SERVER_NAME'] ?&gt;/test/image/1.jpg"&gt;
  </code></pre>
  
  <blockquote>
    <p>Failed to load resource: the server responded with a status of 404
    (Not Found)</p>
  </blockquote>
  
  <p>I get this error only when I echo the $_SERVER['SERVER_NAME']. When I remove echo and write it as</p>
  
  <pre><code>&lt;img src="&lt;?php $_SERVER['SERVER_NAME'] ?&gt;/test/image/1.jpg"&gt;
  </code></pre>
  
  <p>then server finds the image.</p>
  
  <p>So my question is why echo is fine in first case but not in late case?</p>