I am working on one assignment in which I want to display particular <div>
tag on basis of, if the user is on or off and up-user or down user.
Here is my html code on name dom.html
I also want to take care of nested and unnested content
<html>
<head>
<title>Welcome to gaming website</title>
</head>
<body>
<div class="on">
<p>You are in on class</p>
</div>
<div class="off">
<div class="up-user">
<p>you are in off up-user class</p>
</div>
<div class="down-user">
<p>you are in off down-user class</p>
</div>
</div>
</body>
</html>
I wrote the following php code in order to achieve this goal.
<?php
$myjson = '{"user": "down-user", "status": "on"}';
$result =json_decode($myjson, true);
$user = $result["user"];
$status= $result["status"];
$html = file_get_contents('dom.html');
if ($user == 'down-user' and $status == 'on'){
$down-user-off= explode( '<div class="on">' , $html);
$down-user-off-end = explode("</div>" , $down-user-off[1] );
echo $down-user-off-end[0];
}elseif ($user == 'up-user' and $status == 'off'') {
$up-user-off = explode( '<div class="up-user">' , $html );
$up-user-off-end = explode("</div>" , $up-user-off[1] );
echo $up-user-off-end[0];
}
This gives me only the content inside div and do not display the html head and body tags. It is possible to display all the code i.e. html heat body and skip a particular div tag. For example I want to skip
<div class="on">
<p>You are in on class</p>
</div>
from the code and display all the other html code.