PHP Split html string into array -
PHP Split html string into array -
i hope can help guys.
this i'm struggling with, have string of html this:
<h4>some title here</h4> <p>lorem ipsum dolor</p> (some other html here) <h4>some other title here</h4> <p>lorem ipsum dolor</p> (some other html here) i need split <h4> rest of content, illustration content after first <h4> , before sec <h4> needs related first <h4>, this:
array { [0] => <h4>some title here</h4> [1] => <p>lorem ipsum dolor</p> } array { [0] => <h4>some other title here</h4> [1] => <p>lorem ipsum dolor</p> } this build accordion (quite hard explain why i'm doing way, has way), , <h4> accordion panel headings , when clicked expand , show content associated them.
i hope made problem clear, allow me know of thoughts , how should improve way.
i looking domdocument, tried explode() no success.
i have working javascript need accomplish same thing php, it's quite complicated play dom php.
thank in advance.
this should want -- though i'm sure there other (and perchance better) ways
$ahtml = explode("<h4>", $chtml); foreach ($ahtml $npos => $cpanel) { if ($npos > 0) { $apanel = explode("</h4>", $cpanel); $cheader = "<h4>" . $apanel[0] . "</h4>"; $cpanelcontent = $apanel[1]; } } it doesn't set in array format stipulated -- though within loop. otherwise content output/constructed within loop.
edit: added h4 , /h4 in completeness
php html arrays accordion domdocument
Comments
Post a Comment