I have this HTML Template:
<div>
<p class="ex-fr">Tex1 - Edit</p>
Out Text 1 Edit
<p>Tex2 - Edit</p>
Out Text 1 Edit
<br>
Out Text 3 Edit
</div>
I would like to create a page for editing the text of this Template and the Tags attribute.
For doing this, i need to parse this html into a php array and load the page.
This is an hypothetical array that I could get from the html written above:
$parsedHtml = array(
'thisIs'=>'tag',
'tag' => 'div',
'attr' => '',
'children'=> array(
0 => array(
'thisIs'=>'tag',
'tag' => 'p',
'attr' => 'class="ex-fr"',
'children'=> array(
'thisIs'=>'text',
'tag' => '',
'attr' => '',
'children'=> 'Tex1 - Edit'
)
),
1 => array(
'thisIs'=>'text',
'tag' => '',
'attr' => '',
'children'=> 'Out Text 1 Edit'
),
2 => array(
'thisIs'=>'tag',
'tag' => 'p',
'attr' => '',
'children'=> array(
'thisIs'=>'text',
'tag' => '',
'attr' => '',
'children'=> 'Tex2 - Edit'
)
),
3 => array(
'thisIs'=>'text',
'tag' => '',
'attr' => '',
'children'=> 'Out Text 2 Edit'
),
4 => array(
'thisIs'=>'sTag',
'tag' => 'br',
'attr' => '',
'children'=> ''
),
5 => array(
'thisIs'=>'text',
'tag' => '',
'attr' => '',
'children'=> 'Out Text 3 Edit'
)
)
);
At the moment I have tried to use this Class: https://code.google.com/p/php-html2array/downloads/detail?name=class.htmlParser.php 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"
So the given array is
(
[-{}-2-0-{}-] => Array
(
[id] => -{}-2-0-{}-
[father] =>
[tag] => div
[innerHTML] => <p class='ex-fr'>Tex1 - Edit</p> Out Text 1 Edit <p>Tex2 - Edit</p> Out Text 1 Edit <br> Out Text 3 Edit
[htmlText] => <div > <p class='ex-fr'>Tex1 - Edit</p> Out Text 1 Edit <p>Tex2 - Edit</p> Out Text 1 Edit <br> Out Text 3 Edit </div>
[stratr] =>
[childNodes] => Array
(
[0] => Array
(
[id] => -{}-1-0-{}-
[father] => -{}-2-0-{}-
[tag] => p
[innerHTML] => Tex1 - Edit
[htmlText] => <p class='ex-fr'>Tex1 - Edit</p>
[stratr] => class='ex-fr'
[childNodes] => Array
(
)
)
[1] => Array
(
[id] => -{}-1-1-{}-
[father] => -{}-2-0-{}-
[tag] => p
[innerHTML] => Tex2 - Edit
[htmlText] => <p>Tex2 - Edit</p>
[stratr] =>
[childNodes] => Array
(
)
)
[2] => Array
(
[id] => -{}-0-0-{}-
[father] => -{}-2-0-{}-
[tag] => br
[innerHTML] => <br>
[htmlText] => <br>
[stratr] =>
[childNodes] => Array
(
)
)
)
)
)
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)
I know that parse html with a regex is hard or impossible, is there another solution?
Thank you all in advance, sorry for my poor english
Best regards Andrea.