title: Parse html to PHP array
body: <p>I have this HTML Template:</p>
  
  <pre><code>&lt;div&gt;
    &lt;p class="ex-fr"&gt;Tex1 - Edit&lt;/p&gt;
  
    Out Text 1 Edit
  
    &lt;p&gt;Tex2 - Edit&lt;/p&gt;
  
    Out Text 1 Edit
  
    &lt;br&gt;
  
    Out Text 3 Edit
  
  &lt;/div&gt;
  </code></pre>
  
  <p>I would like to create a page for editing the text of this Template and  the Tags attribute.</p>
  
  <p>For doing this, i need to parse this html into a php array and load the page.</p>
  
  <p>This is an hypothetical array that I could get from the html written above:</p>
  
  <pre><code>$parsedHtml = array(
          'thisIs'=&gt;'tag',
          'tag' =&gt; 'div',
          'attr' =&gt; '',
          'children'=&gt; array(
              0 =&gt; array(
                  'thisIs'=&gt;'tag',
                  'tag' =&gt; 'p',
                  'attr' =&gt; 'class="ex-fr"',
                  'children'=&gt; array(
                      'thisIs'=&gt;'text',
                      'tag' =&gt; '',
                      'attr' =&gt; '',
                      'children'=&gt; 'Tex1 - Edit'
                  )
              ),
              1 =&gt; array(
                  'thisIs'=&gt;'text',
                  'tag' =&gt; '',
                  'attr' =&gt; '',
                  'children'=&gt; 'Out Text 1 Edit'
              ),
              2 =&gt; array(
                  'thisIs'=&gt;'tag',
                  'tag' =&gt; 'p',
                  'attr' =&gt; '',
                  'children'=&gt; array(
                      'thisIs'=&gt;'text',
                      'tag' =&gt; '',
                      'attr' =&gt; '',
                      'children'=&gt; 'Tex2 - Edit'
                  )
              ),
              3 =&gt; array(
                  'thisIs'=&gt;'text',
                  'tag' =&gt; '',
                  'attr' =&gt; '',
                  'children'=&gt; 'Out Text 2 Edit'
              ),
              4 =&gt; array(
                  'thisIs'=&gt;'sTag',
                  'tag' =&gt; 'br',
                  'attr' =&gt; '',
                  'children'=&gt; ''
              ),
              5 =&gt; array(
                  'thisIs'=&gt;'text',
                  'tag' =&gt; '',
                  'attr' =&gt; '',
                  'children'=&gt; 'Out Text 3 Edit'
              )
  
          )
  
      );
  </code></pre>
  
  <p>At the moment I have tried to use this Class:
  <a href="https://code.google.com/p/php-html2array/downloads/detail?name=class.htmlParser.php" rel="nofollow">https://code.google.com/p/php-html2array/downloads/detail?name=class.htmlParser.php</a>
  The problem is that the class is returning only the tag, while the text without tags should be ignored like "Out Text 1 Edit" OR "Out Text 2 Edit"</p>
  
  <p>So the given array is</p>
  
  <pre><code>(
  [-{}-2-0-{}-] =&gt; Array
      (
          [id] =&gt; -{}-2-0-{}-
          [father] =&gt; 
          [tag] =&gt; div
          [innerHTML] =&gt;  &lt;p class='ex-fr'&gt;Tex1 - Edit&lt;/p&gt; Out Text 1 Edit &lt;p&gt;Tex2 - Edit&lt;/p&gt; Out Text 1 Edit &lt;br&gt; Out Text 3 Edit 
          [htmlText] =&gt; &lt;div &gt; &lt;p class='ex-fr'&gt;Tex1 - Edit&lt;/p&gt; Out Text 1 Edit &lt;p&gt;Tex2 - Edit&lt;/p&gt; Out Text 1 Edit &lt;br&gt; Out Text 3 Edit &lt;/div&gt;
          [stratr] =&gt; 
          [childNodes] =&gt; Array
              (
                  [0] =&gt; Array
                      (
                          [id] =&gt; -{}-1-0-{}-
                          [father] =&gt; -{}-2-0-{}-
                          [tag] =&gt; p
                          [innerHTML] =&gt; Tex1 - Edit
                          [htmlText] =&gt; &lt;p class='ex-fr'&gt;Tex1 - Edit&lt;/p&gt;
                          [stratr] =&gt;  class='ex-fr'
                          [childNodes] =&gt; Array
                              (
                              )
  
                      )
  
                  [1] =&gt; Array
                      (
                          [id] =&gt; -{}-1-1-{}-
                          [father] =&gt; -{}-2-0-{}-
                          [tag] =&gt; p
                          [innerHTML] =&gt; Tex2 - Edit
                          [htmlText] =&gt; &lt;p&gt;Tex2 - Edit&lt;/p&gt;
                          [stratr] =&gt; 
                          [childNodes] =&gt; Array
                              (
                              )
  
                      )
  
                  [2] =&gt; Array
                      (
                          [id] =&gt; -{}-0-0-{}-
                          [father] =&gt; -{}-2-0-{}-
                          [tag] =&gt; br
                          [innerHTML] =&gt; &lt;br&gt;
                          [htmlText] =&gt; &lt;br&gt;
                          [stratr] =&gt; 
                          [childNodes] =&gt; Array
                              (
                              )
  
                      )
  
              )
  
      )
  
  )
  </code></pre>
  
  <p>Any idea to parse the html into an array?
  (I have searched how the browsers parse the html code and show it in the console, like chrome or firebug, and they permit the edit)</p>
  
  <p>I know that parse html with a regex is hard or impossible, is there another solution?</p>
  
  <p>Thank you all in advance, sorry for my poor english</p>
  
  <p>Best regards Andrea.</p>