title: Keep the left part of a string before a specific Character
body: <p>I am looking to get the value of a particular cookie (affiliate ID) and can successfully pull this in however some cookies have some additional content in the string which I need to strip off. </p>
  
  <p>For example: <code>AFFILIATE_www.example.com_</code> where I only want to obtain AFFILIATE. In all cases, the additional information is surrounded by two underscores. Is there a way I can strip off every character after and including the first underscore? </p>
  
  <p>I've tried the following: </p>
  
  <pre><code>&lt;?php $cookie_name = 'cbnn';
  if(!isset($_COOKIE[$cookie_name])) {
    '';
  } else {
     $_COOKIE[$cookie_name];
  }; ?&gt;
  
  &lt;?php $aff = "$_COOKIE[$cookie_name]";
  $search = “EVERYTHING AFTER AND INCLUDING THE _”
  $replace = "";
  echo preg_replace($search,$replace,$aff); ?&gt; 
  </code></pre>