title: php preg_replace regex lookahead
body: <p>Iam trying to replace Ampersands on my html sidewide using preg_replace, but the issue is that it breaks inline javascript &amp;&amp; or javascript url like ?page=test&amp;id=1</p>
  
  <p>Now i have this code, which works</p>
  
  <pre><code>$amp_replace = array();
  $amp_replace[0] = '/(?&lt;=\s)&amp;(?!&amp;)(?!#?[a-z0-9]+;)/';
  $amp_replace[1] = '/(?&lt;!&amp;)&amp;(?=\s)/';
  $skin = preg_replace($amp_replace, '&amp;amp;', $skin);
  </code></pre>
  
  <p>Replaces ampersands when space on left or right. dont replace when 2 ampersand in a row ( for javascript ) or when following by html entity.</p>
  
  <p>But i find it rather unneeded logic here. It also dont replace ampersands if its like test&amp;test.</p>
  
  <p>As iam no regex expert, this took me allready quite a while, so i thought i seek help here once again.</p>
  
  <p>Wouldnt it be better to simply replace all ampersands if not within javascript script tags? I tried that allready but no real success</p>
  
  <p>Does anyone know how i could archive that?
  Thank you</p>