title: PHP, Break Up String with Ampersand
body: <p>I have spent a lot of time searching the web for this, so before someone slams me for not looking ... trust me, I have.</p>
  
  <p>The problem: I am working with a string that includes an ampersand, to display two names. The difficulty: at times I may need to pull the name on the left, or the name on the right for display. The additional difficulty is that some of the names may include HTML entities, which of course also use an ampersand. </p>
  
  <p>Example: I may use something as simple as:</p>
  
  <p>"Fred &amp; Wilma"</p>
  
  <p>To get just "Fred" from the string, I tried using the PHP function STRPOS(), but I get nothing. </p>
  
  <pre><code>$nPos = strpos( " &amp; ", $names );
  </code></pre>
  
  <p>Note that I am using spaces on either side to avoid issues with HTML entities. </p>
  
  <p>More fun, checking to see if I get no results:</p>
  
  <pre><code>if ( $nPos === 0 )
  {
     echo "String ' $' not found in " . $names . "&lt;br /&gt;";
  }
  </code></pre>
  
  <p>Does not return a value. This tells me, from the various documentation and such on the web that I can find, that I should have a value for $nPos that is useful.</p>
  
  <p>If I add:</p>
  
  <pre><code>echo "Position of string ' &amp; ': " . $nPos . "&lt;br /&gt;";
  </code></pre>
  
  <p>I get a blank value after the text in double quotes. </p>
  
  <p>I am at a loss how to do what I need here. I need to get the position of the " &amp; " characters, but am not getting it. From there obviously use of the substr() function would be necessary to get the values from the left and/or right of the ampersand. </p>