Try this;
$str = "<div class='room'>
<h1>This is a h1</h1>
<p>This is a Paragraph</p>
<h2>This is h2</h2>
</div>";
$arr = explode(PHP_EOL, $str);
$res =array();
Foreach($arr as $row){
If(!strpos($row, "div") !== False){
$res[substr($row, 1, strpos($row, ">")-1)] = strip_tags($row);
}
}
Var_dump($res);
https://3v4l.org/8TkIT
It loops through one line at the time and creates the array with named keys.
Edit if there is more than one room you can make it multidimensional like this:
https://3v4l.org/DdXVd
$str = "<div class='room'>
<h1>This is a h1</h1>
<p>This is a Paragraph</p>
<h2>This is h2</h2>
</div>
<div class='room2'>
<h1>This is a h1</h1>
<p>This is a Paragraph</p>
<h2>This is h2</h2>
</div>";
$arr = explode(PHP_EOL, $str);
$res =array();
Foreach($arr as $row){
If(strpos($row, "div") !== False){
$pos1 = strpos($row, "'")+1;
$room = substr($row, $pos1, strpos($row, "'", $pos1)-$pos1);
}Else{
$pos1 = strpos($row, "<")+1;
$res[$room][substr($row, strpos($row, "<")+1, strpos($row, ">")-$pos1)] = trim(strip_tags($row));
}
}
Var_dump($res);