Maison développement back-end tutoriel php PHP 中的 SimpleXML 处理_PHP教程

PHP 中的 SimpleXML 处理_PHP教程

Jul 13, 2016 pm 05:33 PM
php simplexml grand public 了解 et 处理 开发 版本 maintenant de 语言

  了解和 php(做为现在的主流开发语言) 版本 5 捆绑到一起的 Simplexml(标准化越来越近了) 扩展,它使 php(做为现在的主流开发语言) 页面能够以 php(做为现在的主流开发语言) 友好的语法来查询、搜索、修改和重新发布 xml(标准化越来越近了)

  php(做为现在的主流开发语言) 版本 5 引入了 Simplexml(标准化越来越近了),一种用于读写 xml(标准化越来越近了) 的新的应用程序编程接口(API)。在 Simplexml(标准化越来越近了) 中,下面的这样的表达式:

  $doc->rss->channel->item->title


  从文档中选择元素。只要熟悉文档的结构,很容易编写这种表达式。但是,如果不很清楚需要的元素出现在何处(比如 Docbook、HTML 和类似的叙述性文档中),Simplexml(标准化越来越近了) 可以使用 XPath 表达式寻找这些元素。

  开始使用 Simplexml(标准化越来越近了)

  假设需要一个 php(做为现在的主流开发语言) 页面将 RSS 提要(feed)转化成 HTML。RSS 是一种简单的 xml(标准化越来越近了) 格式用于发布连锁内容。文档的根元素是 rss,它包括一个 channel 元素。channel 元素包含关于提要的元数据,如标题、语言和 URL。它还包含各种封装在 item 元素中的报道。每个 item 都有一个 link 元素,包括一个 URL,还有 title 或 description(通常两者都有),包含普通文本。不使用名称空间。RSS 的内容当然不止这些,不过对本文来说知道这些就足够了。清单 1 显示了一个典型的例子,它包含两个新闻项。

  清单 1. RSS 提要

(标准化越来越近了) version="1.0" encoding="UTF-8"?>


  Mokka mit Schlag
  http://www.elharo.com/blog
  en
 
    Penn Station: Gone but not Forgotten
   
     The old Penn Station in New York was torn down before I was born.
     Looking at these pictures, that feels like a mistake.  The current site is
     functional, but no more; really just some office towers and underground
     corridors of no particular interest or beauty. The new Madison Square...
   

    http://www.elharo.com/blog/new-york/2006/07/31/penn-station
 

 
    Personal for Elliotte Harold
    Some people use very obnoxious spam filters that require you
     to type some random string in your subject such as E37T to get through.
     Needless to say neither I nor most other people bother to communicate with
     these paranoids. They are grossly overreacting to the spam problem.
     Personally I wont ...

    http://www.elharo.com/blog/tech/2006/07/28/personal-for-elliotte-harold/
 


 

  我们来开发一个 php(做为现在的主流开发语言) 页面将 RSS 提要格式化为 HTML。清单 2 显示了这个页面的基本结构。

  清单 2. php(做为现在的主流开发语言) 代码的静态结构

(做为现在的主流开发语言) // Load and parse the xml(标准化越来越近了) document ?>
(标准化越来越近了):lang="en" lang="en">


  <?php <font class=reblank>(做为现在的主流开发语言) // The title will be read from the RSS ?>

(做为现在的主流开发语言) // The title will be read from the RSS again ?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/508648.htmlTechArticle了解和 php (做为现在的主流开发语言) 版本 5 捆绑到一起的 Simplexml (标准化越来越近了) 扩展,它使 php (做为现在的主流开发语言) 页面能够...
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn

Article chaud

Repo: Comment relancer ses coéquipiers
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Crystals d'énergie expliqués et ce qu'ils font (cristal jaune)
1 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: Comment obtenir des graines géantes
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Combien de temps faut-il pour battre Split Fiction?
3 Il y a quelques semaines By DDD

Article chaud

Repo: Comment relancer ses coéquipiers
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Crystals d'énergie expliqués et ce qu'ils font (cristal jaune)
1 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: Comment obtenir des graines géantes
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Combien de temps faut-il pour battre Split Fiction?
3 Il y a quelques semaines By DDD

Tags d'article chaud

Bloc-notes++7.3.1

Bloc-notes++7.3.1

Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise

SublimeText3 version chinoise

Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1

Envoyer Studio 13.0.1

Puissant environnement de développement intégré PHP

Dreamweaver CS6

Dreamweaver CS6

Outils de développement Web visuel

SublimeText3 version Mac

SublimeText3 version Mac

Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Guide d'installation et de mise à niveau de PHP 8.4 pour Ubuntu et Debian Guide d'installation et de mise à niveau de PHP 8.4 pour Ubuntu et Debian Dec 24, 2024 pm 04:42 PM

Guide d'installation et de mise à niveau de PHP 8.4 pour Ubuntu et Debian

Date et heure de CakePHP Date et heure de CakePHP Sep 10, 2024 pm 05:27 PM

Date et heure de CakePHP

Configuration du projet CakePHP Configuration du projet CakePHP Sep 10, 2024 pm 05:25 PM

Configuration du projet CakePHP

Téléchargement de fichiers CakePHP Téléchargement de fichiers CakePHP Sep 10, 2024 pm 05:27 PM

Téléchargement de fichiers CakePHP

Routage CakePHP Routage CakePHP Sep 10, 2024 pm 05:25 PM

Routage CakePHP

Discuter de CakePHP Discuter de CakePHP Sep 10, 2024 pm 05:28 PM

Discuter de CakePHP

Guide rapide CakePHP Guide rapide CakePHP Sep 10, 2024 pm 05:27 PM

Guide rapide CakePHP

Comment configurer Visual Studio Code (VS Code) pour le développement PHP Comment configurer Visual Studio Code (VS Code) pour le développement PHP Dec 20, 2024 am 11:31 AM

Comment configurer Visual Studio Code (VS Code) pour le développement PHP

See all articles