2017-01-31 2 views
0

가 어떻게 제공 JSON 데이터의 배열에서 titlecontent을 추출 할 수 있습니다 JSON 데이터의 배열에서 값을 추출 할 수 있습니다 I var_dump(WpApi::posts());가 어떻게이 위해서 var_dump이

array(3) { ["results"]=> array(1) 
{ [0]=> array(23) 
{ ["id"]=> int(8) 
["date"]=> string(19) "2017-01-31T07:08:21" 
["date_gmt"]=> string(19) "2017-01-31T07:08:21" 
["guid"]=> array(1) { ["rendered"]=> string(34) "http://idybrand.com/wordpress/?p=8" } 
["modified"]=> string(19) "2017-01-31T07:08:21" 
["modified_gmt"]=> string(19) "2017-01-31T07:08:21" 
["slug"]=> string(34) "february-is-just-around-the-corner" 
["type"]=> string(4) "post" 
["link"]=> string(76) "http://idybrand.com/wordpress/2017/01/31/february-is-just-around-the-corner/" 
["title"]=> array(1) { ["rendered"]=> string(34) "February is just around the corner" } 
["content"]=> array(2) { ["rendered"]=> string(39) " 
Appreciate this wonderful month 
" ["protected"]=> bool(false) } 
["excerpt"]=> array(2) { ["rendered"]=> string(39) " 
Appreciate this wonderful month 
" ["protected"]=> bool(false) } 
["author"]=> int(1) 
["featured_media"]=> int(0) 
["comment_status"]=> string(4) "open" 
["ping_status"]=> string(4) "open" 
["sticky"]=> bool(false) 
["template"]=> string(0) "" 
["format"]=> string(8) "standard" 
["meta"]=> array(0) { } 
["categories"]=> array(1) { [0]=> int(1) } 
["tags"]=> array(0) { } 
["_links"]=> array(9) { ["self"]=> array(1) { [0]=> array(1) { ["href"]=> string(51) "http://idybrand.com/wordpress/wp-json/wp/v2/posts/8" } } ["collection"]=> array(1) { [0]=> array(1) { ["href"]=> string(49) "http://idybrand.com/wordpress/wp-json/wp/v2/posts" } } ["about"]=> array(1) { [0]=> array(1) { ["href"]=> string(54) "http://idybrand.com/wordpress/wp-json/wp/v2/types/post" } } ["author"]=> array(1) { [0]=> array(2) { ["embeddable"]=> bool(true) ["href"]=> string(51) "http://idybrand.com/wordpress/wp-json/wp/v2/users/1" } } ["replies"]=> array(1) { [0]=> array(2) { ["embeddable"]=> bool(true) ["href"]=> string(59) "http://idybrand.com/wordpress/wp-json/wp/v2/comments?post=8" } } ["version-history"]=> array(1) { [0]=> array(1) { ["href"]=> string(61) "http://idybrand.com/wordpress/wp-json/wp/v2/posts/8/revisions" } } ["wp:attachment"]=> array(1) { [0]=> array(1) { ["href"]=> string(58) "http://idybrand.com/wordpress/wp-json/wp/v2/media?parent=8" } } ["wp:term"]=> array(2) { [0]=> array(3) { ["taxonomy"]=> string(8) "category" ["embeddable"]=> bool(true) ["href"]=> string(61) "http://idybrand.com/wordpress/wp-json/wp/v2/categories?post=8" } [1]=> array(3) { ["taxonomy"]=> string(8) "post_tag" ["embeddable"]=> bool(true) ["href"]=> string(55) "http://idybrand.com/wordpress/wp-json/wp/v2/tags?post=8" } } ["curies"]=> array(1) { [0]=> array(3) { ["name"]=> string(2) "wp" ["href"]=> string(23) "https://api.w.org/{rel}" ["templated"]=> bool(true) } } } } } 
["total"]=> string(1) "1" 
["pages"]=> string(1) "1" } 

를 PHP를하시기 바랍니다 사용할 때 다음과 같은
+0

여기에는 많은 수평 스크롤이 필요합니다. 소스를보다 읽기 쉬운 형식으로 포맷 할 수 있습니까? – Gustave

+0

@Gustave 위대한 아이디어지만, 나는 잘 모르겠다. 나는 시험해 볼 것이다 ;-) –

답변

4

이것은 JSON에 따라 작업을 수행합니다.

echo ['results'][0]['title']['rendered']; //Title 
echo ['results'][0]['content']['rendered']; //Content 
+1

빙고! 건배 –

1

다차원 배열이있어 데이터를 가져올 수 있습니다.

$arr = WpApi::posts(); 
$arr['results'][0]['content']['rendered'] //this is your content string 
$arr['results'][0]['title']['rendered'] // this is your title string 
+0

고마워. 나는 당신이 가까이 있다고 생각하지만'Undefined index : content'를 얻습니다.'결과를 먼저 고려해야 할 것 같습니까? –

+2

감사하지만 Kitson88은 단지 당신을 이겼다 :-) –

관련 문제