I am working on parsing HTML and get multidimensional output array as json. I am parsing html like I want but I couldn't create JSON array.
The example output of foreach loop:
PS: every json object has different string value.
0:"blahblah"
1:"blahblah"
2:"blahblah"
3:"blahblah"
4:" " // only space
5:"blahblah"
6:"blahblah"
7:"blahblah"
8:"blahblah"
9:" " // only space
...
I want create json array like this:
$output = array();
$html = str_get_html($ret);
$lessons["lesson"] =array();
foreach($html->find('table//tbody//tr') as $element) {
$temp = strip_tags($element->innertext);
array_push($lessons['lesson'], $temp); // the objects (I wrote as 'blahblah' every object but I getting different values always)
if($temp == " ") // if there is only space push array the output and create new array
{
array_push($output , $lessons["lesson"]);
unset($lessons);
$lessons["lesson"] = array();
}
}
echo (json_encode($output ,JSON_UNESCAPED_UNICODE)); // $output show nothing
Thanks in advice.