title: PHP - Extract attributes and text from string for each <div>
body: <p>I have a string <code>$value</code> which looks like that:</p>
  
  <pre><code>'&lt;div id='1' data-AAA='something1' data-BBB='something2'&gt;My&lt;/div&gt;&lt;div id='5' data-AAA='something5' data-BBB='something6'&gt;Web&lt;/div&gt;
  ...'
  </code></pre>
  
  <p>In PHP, I would like for each <code>&lt;div&gt;</code>, extract all data attributes (here <code>id</code>, <code>data-AAA</code> and <code>data-BBB</code>) and also the text, and then put them into an array like that:</p>
  
  <pre><code>Array
    [0]
       ID =&gt; 1
       data-AAA =&gt; something1
       data-BBB =&gt; something2
       text =&gt; My
    [1]
       ID =&gt; 5
       data-AAA =&gt; something5
       data-BBB =&gt; something6
       text =&gt; Web
  </code></pre>
  
  <p>Is it possible to extract all those informations from a string with a loop ? being debutant, I have no idea how to do that for a string...</p>
  
  <p><strong>EDIT 1</strong> </p>
  
  <p>thanks to the DOM doc (<a href="http://php.net/manual/en/class.domdocument.php" rel="nofollow">http://php.net/manual/en/class.domdocument.php</a>) given in answers, I tried this and that works !</p>
  
  <pre><code>        $dom = new DOMDocument;
          $dom-&gt;loadHTML($value);
          foreach ($dom-&gt;getElementsByTagName('div') as $ST) {
              $valueID = $ST-&gt;getAttribute('id');
              $valueDataTimeStart = $ST-&gt;getAttribute('data-AAA');
              $valueDataTimeStart = $ST-&gt;getAttribute('data-BBB');
              $valueDataTimeEnd = $ST-&gt;getAttribute('id');
              var_dump($valueID);
              var_dump($valueDataTimeStart);
              var_dump($valueDataTimeEnd);
          }die;
  </code></pre>