title: How to dynamically poputate title and meta tags with php and/or javascript
body: <p>I'm trying to replace my title tag and meta description dynamically using parameters from a search query in PHP. They keep showing up blank, but if I echo the $title or $desc inside the original PHP (first set) of tags, it appears fine. There is no header.php file for reference.</p>
  
  <pre><code>&lt;?php
  $url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  list($chuck, $keep) = explode('?', $url);
  $patterns = array(); 
  $patterns[0] = 'foo';
  $patterns[1] = 'bar';
  $patterns[2] = '123';
  $replacements = array();
  $replacements[0] = 'good ';
  $replacements[1] = 'bad ';
  $replacements[2] = 'ugly ';
  $mytitle = "my cool " . $keep . " title tag";
  $mydesc = "my cool " . $keep . " meta " . $keep . " description";
  $title = str_replace($patterns, $replacements, $mytitle);
  $desc = str_replace($patterns, $replacements, $mydesc);
  
  //echo $title . "&lt;/br&gt;";
  //echo $desc . "&lt;/br&gt;";
  ?&gt;      
  &lt;title&gt;&lt;?if (strpos($url, 'foo=') !== false) { echo $title . "&lt;/br&gt;"; } else { some other title"; }?&gt;&lt;/title&gt;
  &lt;meta name="description" content="&lt;?php echo $desc; ?&gt;"&gt;
  </code></pre>
  
  <p>Alternatively, would a javascript/php mashup like this work?</p>
  
  <pre><code>&lt;script&gt;
      document.title = &lt;?if (strpos($url, 'foo=') !== false) { echo $title . "&lt;/br&gt;"; } else { some other title"; }?&gt;;
  &lt;/script&gt;
  </code></pre>