I want to extract some information from some html code using dom parser, but I'm stuck at a point.
<div id="posts">
<div class="post">
<div class="user">me:</div>
<div class="post">I am an apple</div>
</div>
<div class="post">
<div class="user">you:</div>
<div class="post">I am a banana</div>
</div>
<div class="post">
<div class="user">we:</div>
<div class="post">We are fruits</div>
</div>
</div>
This will print the users.
$users= $html->find('div[class=user]');
foreach($users as $user)
echo $user->innertext;
This will print the posts.
$posts = $html->find('div[class=post]');
foreach($posts as $post)
echo $post->innertext;
I want to print them together, and not sepparately, like so:
me:
I am an apple
you:
I am a banana
we:
We are fruits
How can I do this using the parser?
DOMDocumentmaybe?strip_tags()to get your output in very simple way