title: How replace the value inside a html tag?
body: <p>I want to replace element content with content which is definded in $tagsReplace array but have problem with preg_replace, my current ode:</p>
  
  <pre><code>$tagsReplace = array(
      'header' =&gt; 'header',
      'tag1' =&gt; 'this is tag1',
      'tag2' =&gt; 'this is tag2',
      'tag3' =&gt; 'this is tag3',
      'footer' =&gt; 'footer',
  ); 
  
  $content = '
  &lt;!DOCTYPE html&gt;
  &lt;hthml&gt;
  &lt;header data-edit="true" data-tag-id="header"&gt;&lt;/header&gt;
  &lt;div data-edit="true" data-tag-id="tag1"&gt;&lt;/div&gt;
  &lt;div data-edit="true" data-tag-id="tag2"&gt;&lt;/div&gt;
  &lt;div data-edit="true" data-tag-id="tag3"&gt;&lt;/div&gt;
  &lt;footer data-edit="true" data-tag-id="footer"&gt;&lt;/footer&gt;
  &lt;/html&gt;
  ';
  
  $dom = new DOMDocument();
  libxml_use_internal_errors(true);
  $dom-&gt;loadHTML($content);
  $xpath = new DomXpath($dom);
  
  foreach ($xpath-&gt;query('//*[@data-edit="true"]') as $rowNode) { 
      $tagID = $rowNode-&gt;getAttribute('data-tag-id');
      $content = preg_replace('/(&lt;div.*?data-edit="true"[^&gt;]*&gt;)(.*?)(&lt;\/div&gt;)/i', '$1'. $tagsReplace[$tagID] . '$3', $content);
  }
  echo $content;
  </code></pre>
  
  <p>What i want is to get output like that:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;hthml&gt;
  &lt;header data-edit="true" data-tag-id="header"&gt;header&lt;/header&gt;
  &lt;div data-edit="true" data-tag-id="tag1"&gt;this is tag1&lt;/div&gt;
  &lt;div data-edit="true" data-tag-id="tag2"&gt;this is tag2&lt;/div&gt;
  &lt;div data-edit="true" data-tag-id="tag3"&gt;this is tag3&lt;/div&gt;
  &lt;footer data-edit="true" data-tag-id="footer"&gt;footer&lt;/footer&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Current output is:</p>
  
  <pre><code> &lt;!DOCTYPE html&gt;
  &lt;hthml&gt;
  &lt;header data-edit="true" data-tag-id="header"&gt;&lt;/header&gt;
  &lt;div data-edit="true" data-tag-id="tag1"&gt;footer&lt;/div&gt;
  &lt;div data-edit="true" data-tag-id="tag2"&gt;footer&lt;/div&gt;
  &lt;div data-edit="true" data-tag-id="tag3"&gt;footer&lt;/div&gt;
  &lt;footer data-edit="true" data-tag-id="footer"&gt;&lt;/footer&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Soo all elements which contain atribute data-edit="true" and data-tag-id has to get content inside them replaced by tagid value which is definded in arra $tagsReplace.</p>