파싱 해서 가져오는 방법 질문입니다. 채택완료
{
"success": true,
"start": 0,
"limit": 20,
"total": 99,
"posts": [
{
"idx": 1,
"bid": "notice",
"title": "테스트 공지",
},
{
"idx": 2,
"bid": "free",
"title": "aaaaa",
},
{
"idx": 44,
"bid": "qna",
"title": "what?",
}
]
}
요런 html로 정보를 받고 있습니다.
include "simple_html_dom.php";
이걸 써서 파싱을 하라고 하는데
예를 들어 notice 의 글만 가져 올려고 하면 어떻게 해야 할까요?
답변 4개
$dom = new simple_html_dom();
$dom->load($html);
foreach ($dom->find('div[title]') as $post) {
$title = $post->plaintext;
echo "Title: $title\n";
}
$dom->clear();
스스로 찾아서 했습니다.
댓글을 작성하려면 로그인이 필요합니다.
</p>
<p>$tmp_data = '';</p>
<p>$url = "URL주소";</p>
<p>$tmp_data = file_get_contents_curl($url);</p>
<p>$tmp_data = json_decode($tmp_data);</p>
<p>$data = array();</p>
<p>foreach($tmp_data['posts'] as $k => $v){</p>
<p> if($v['bid'] == 'notice') $data[] = $v;</p>
<p>}</p>
<p>print_r($data);</p>
<p>
대략 이정도 일듯 하네요.
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
Array ( )
이렇게만 화면에 나옵니다.