SimpleXML in PHP _ PHP Tutorial

Source: Internet
Author: User
SimpleXML processing in PHP. Understand the Simplexml (standardization is getting closer and closer) extension bundled with php (as the mainstream development language) version 5, which makes php (as the mainstream development language) the page can understand the Simplexml (standardization is getting closer and closer) extension bundled with php (as the mainstream development language) version 5, which makes php (as the mainstream development language) pages can be queried, searched, modified, and re-published with php (as the mainstream development language) friendly syntax (the standardization is getting closer and closer ).

Php (as the mainstream development language) version 5 introduces Simplexml (standardization is getting closer and closer), a type for reading and writing xml (standardization is getting closer and closer) the new application programming interface (API ). In Simplexml (standardization is getting closer and closer), the following expression:

$ Doc-> rss-> channel-> item-> title


Select an element from the document. As long as you are familiar with the structure of the document, it is easy to write this expression. However, if you do not know where the required elements appear (such as Docbook, HTML, and similar narrative documents), Simplexml (standardization is getting closer and closer) can use XPath expressions to find these elements.

Start to use Simplexml (standardization is getting closer and closer)

Suppose you need a php (as the mainstream development language) page to convert the RSS feed into HTML. RSS is a simple xml (standardization is getting closer and closer) format used to publish chained content. The root element of the document is rss, which contains a channel element. The channel element contains metadata about the feed, such as the title, language, and URL. It also contains various reports encapsulated in the item element. Each item has a link element, including a URL, and a title or description (usually both), including common text. Do not use namespaces. Of course, RSS is more than that, but it is enough for this article to know. Listing 1 shows a typical example that contains two news items.

Listing 1. RSS feed




Mokka mit Schlag
Http://www.elharo.com/blog </link>
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 participating interest or beauty. The new Madison Square...

Http://www.elharo.com/blog/new-york/2006/07/31/penn-station </link>


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
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/ </link>



Let's develop a php (as the mainstream development language) page to format the RSS feed into HTML. Listing 2 shows the basic structure of the page.

Listing 2. static structure of php code (as the mainstream development language)




<? Php (as The mainstream development language) // the title will be read from The RSS?>

Extension of Simplexml (standardization is getting closer and closer) bundled into php (as the mainstream development language) Version 5) the page can...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.