【发布时间】:2017-06-06 18:37:00
【问题描述】:
我正在解析 HTML 并将多维输出数组作为 json。 我正在解析我想要的 html,但我无法创建 JSON 数组。
foreach 循环的示例输出:
PS:每个 json 对象都有不同的字符串值。
0:"废话"
1:“废话”
2:“废话”
3:“废话”
4:" " // 只有空格
5:“废话”
6:“废话”
7:“废话”
8:“废话”
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
感谢您的建议。
【问题讨论】:
标签: php arrays json multidimensional-array