我正在解析文章,我需要将所有解析的数据放在 josn.xml 中。我尝试将它们放入数组,然后将其转换为 JSON,但我遇到了一些麻烦。我得到这样的JSON:
[{"title":"title1"}][{"title":"title2"}][{"title":"title3"}]
但我想要这样:
[{"title":"title1"},{"title":"title2"},{"title":"title3"}]
我怎么能做到这一点?
<?
foreach ($content_prev as $el) {
$pq = pq($el);
$date = $pq->find('time')->html();
$title = $pq->find('h3 a')->html();
$link = $pq->find('h3 a')->attr('href');
$data_link = file_get_contents($link);
$document_с = phpQuery::newDocument($data_link);
$content = $document_с->find('.td-post-content');
$arr = array (
array(
"title" => $title
),
);
echo json_encode($arr, JSON_UNESCAPED_UNICODE);
}
婷婷同学_