I\'m using jsTree and I need to convert this HTML tag tree code
to a PHP array.
The jsTree HTML tag will be passed to PHP to be parsed and
If you have a UL that does not contain any href elements (e.g. just plain text nexted ul).. I've adjusted Salman's simplehtmldom code to work with that:
$DOM = str_get_html( $catshtml );
$ARR = array( );
function WalkUL( $ul, &$ar )
{
foreach( $ul->children as $li )
{
if ( $li->tag != "li" )
{
continue;
}
$arar = array( );
foreach( $li->children as $ulul )
{
if ( $ulul->tag != "ul" )
{
continue;
}
WalkUL( $ulul, $arar );
}
$ar[ trim(preg_replace("#?[a-z]+[^>]*>(.+[a-z]+[^>]*>|)#is","",$li->innertext)) ] = $arar;
}
}
WalkUL( $DOM->find( "ul", 0 ), $ARR );
echo ""; print_r( $ARR );