JSON 및 XML 데이터를 PHP로 구문 분석하기 위한 구현 코드

WBOY
풀어 주다: 2016-07-25 08:58:49
원래의
1016명이 탐색했습니다.
  1. $json_string='{"id":1,"name":"foo","email":"foo@jbxue.com","interest":["wordpress","php"]} ';
  2. $obj=json_decode($json_string);
  3. echo $obj->name; //prints foo
  4. echo $obj->interest[1]; //prints php
复制代码

2,PHP解析XML 数据

  1. $xml_string="

  2. Test
  3. test@jbxue.com
  4. News
  5. fnews@jbxue.net
  6. ";

  7. //load the xml string using simplexml

  8. $xml = simplexml_load_string($xml_string);

  9. //loop through the each node of user

  10. foreach ($xml->user as $user)
  11. {
  12. //access attribute
  13. echo $user['id'], ' ';
  14. //subnodes are accessed by -> operator
  15. echo $user->name, ' ';
  16. echo $user->email, '
    ';
  17. }

复制代码

如今,json在数据传输上的应用越来越广了,建议大家好好掌握下。



원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!