title: echo php variable in inline style
body: <p>I've seen similar questions but nothing quite the same. In a DB, I have saved hex values for the background and border colors of a specific div. I've verified that I'm getting them out of the database. At the risk of sounding like an idiot: when trying to echo the variables in my inline style, it doesn't work:</p>
  
  <pre><code>&lt;div style="background-color: &lt;?php echo $bg ?&gt;; border: 3px solid &lt;?php echo $border ?&gt;;" id="container"&gt;
  </code></pre>
  
  <p>I had the hunch that even though simply writing a hex code works fine, the string being produced by the variable can't register as a hex value. After some searching I tried a few of the following (without success):</p>
  
  <pre><code>function strToHex($string)
  {
  $hex='';
  for ($i=0; $i &lt; strlen($string); $i++)
  {
      $hex .= dechex(ord($string[$i]));
  }
  return $hex;
  }
  </code></pre>
  
  <p>And</p>
  
  <pre><code>$bg=bin2hex($bg);
  </code></pre>
  
  <p>Anyway, am I missing something? Does the string being stored in my DB need to be converted somehow? How can I change the background color of this div, based on the hex code saved in my database?</p>