0
我正在解析HTML并获取多维输出数组作为json。 我解析HTML像我想但我不能创建JSON数组。解析HTML到多维JSON数组
示例输出foreach循环的:
PS:每JSON对象具有不同的字符串值。
0: “blahblah”
1: “blahblah”
2: “blahblah”
3: “blahblah”
4:”“//仅空间
5:“blahblah”
6:“blahblah”
7: “blahblah”
8: “blahblah”
9:”“//只有空间
...
$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
谢谢你的建议。
谢谢!我改变你的if子句为“if($ elm!=' ')然后它工作!如果你更新你的文章是这样的,我会接受你的回答 – pseudocode
@pseudocode完成! – nerdlyist