search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

Home Backend Development XML/RSS Tutorial PHP uses simplexml to parse xml

PHP uses simplexml to parse xml

Feb 24, 2017 pm 03:29 PM

php uses simplexml to parse xml

PHP uses simplexml to parse xml

code show as below:


$xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
        <loc>//m.sbmmt.com/;/loc>
        <lastmod>2013-06-13 01:20:01</lastmod>
        <changefreq>always</changefreq>
        <priority>1.0</priority>
    </url>
    <url>
        <loc>//m.sbmmt.com/;/loc>
        <lastmod>2013-06-13 01:20:01</lastmod>
        <changefreq>always</changefreq>
        <priority>0.8</priority>
    </url>
</urlset>
XML;

$simple =  simplexml_load_string($xml);
// $url = 'http://www.php230.com/baidu_sitemap1.xml';
// $simple = simplexml_load_file($url);

Here we can check the format of $simple:



print_r($simple);
SimpleXMLElement Object
(
    [url] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [loc] => //m.sbmmt.com/
                    [lastmod] => 2013-06-13 01:20:01
                    [changefreq] => always
                    [priority] => 1.0
                )
            [1] => SimpleXMLElement Object
                (
                    [loc] => //m.sbmmt.com/
                    [lastmod] => 2013-06-13 01:20:01
                    [changefreq] => always
                    [priority] => 0.8
                )
        )
)

We can see that the result is in the format of an object or array, so that we can easily obtain the value of each element in XML



foreach ($simple->url as $val){
    print $val->loc;
}

The loc value of each item will be output here.          

The above is the content of PHP using simplexml to parse xml. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Popular tool

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

AO3 official website entry method AO3 official entrance free access address AO3 official website entry method AO3 official entrance free access address Jan 19, 2026 pm 08:39 PM

The entrance to the AO3 official website is https://archiveofourown.org. Users can directly enter the address in the browser to access. It supports switching between Chinese and English, and free registration and login. The platform provides the function of publishing original and derivative works, and has features such as clear classification, bookmark comment interaction, and multi-condition filtering. It is recommended to enter the URL manually to ensure safety.

Smart Primary and Secondary Schools Web Version Official Login Platform - Smart Primary and Secondary Schools Computer Version Student Learning Portal Smart Primary and Secondary Schools Web Version Official Login Platform - Smart Primary and Secondary Schools Computer Version Student Learning Portal Jan 19, 2026 pm 08:24 PM

The official login platform entrance of the smart primary and secondary school web version is https://basic.smartedu.cn/, which covers the entire curriculum from primary school to high school and supports multi-terminal learning, personalized tools, barrier-free access and home-school collaborative services.

115 Netdisk web version log in immediately_115 Netdisk web version official direct website 115 Netdisk web version log in immediately_115 Netdisk web version official direct website Jan 19, 2026 pm 11:42 PM

The official direct link to the 115 Netdisk web version is https://115.com. The interface is simple and ad-free, and supports multi-view switching, custom sorting, online preview, multi-terminal synchronization, drag and drop upload, fine permission management, historical version retention, duplicate file identification and intelligent resource recommendation.

Haitang Online Literature City starts a reading journey. Official web version login guide Haitang Online Literature City starts a reading journey. Official web version login guide Jan 20, 2026 am 09:27 AM

The official web page login entrance of Haitang Online Literature City is https://www.haitbook.com, which supports responsive design, multi-terminal synchronization, mainstream browser access, email registration verification and personalized reading recommendations.

Blue Ocean Bookstore browser directly enters - Blue Ocean Bookstore does not need to download the web version Blue Ocean Bookstore browser directly enters - Blue Ocean Bookstore does not need to download the web version Jan 20, 2026 am 11:22 AM

There is no need to download the web version of Lanhai Sea Bookstore, just visit https://www.lanhaisea.net to use it; it has wide resource coverage, diverse themes, smooth operation, customizable interface, and supports bookshelf management and cross-end progress synchronization.

Stable entrance to Quark Netdisk web version - Quark Netdisk's latest online channel Stable entrance to Quark Netdisk web version - Quark Netdisk's latest online channel Jan 20, 2026 am 06:39 AM

The stable entrance address of the Quark Netdisk web version is https://pan.quark.cn. The interface adopts a borderless card-style design and supports core functions such as drag-and-drop upload, intelligent filtering, multi-terminal synchronization, online preview and end-to-end encryption.

Free access to Pixiv works Free access to Pixiv works Jan 20, 2026 am 06:15 AM

The entrance to Pixiv's free works is https://www.pixiv.net, which supports high-definition original image browsing, GIF/WEBM animation playback, viewing of tags and creation instructions, thumbnail browsing for non-logged-in users, and low-definition preview downloads; homepage recommendations, top-three rankings, combined searches, and newbie areas to optimize content discovery; like protection, author reply highlighting, multi-level favorites, and follow dynamic push to enhance community interaction; contribution templates, privacy settings, timeline homepage, and novel annotation functions improve creative support.

The official online website of Waste Articles Network_Direct access to the reading entrance of the official website of Waste Articles Network The official online website of Waste Articles Network_Direct access to the reading entrance of the official website of Waste Articles Network Jan 19, 2026 pm 11:30 PM

The official website of Waste Article Network is https://www.xn--pxtr7m5ny.com/, which has functions such as minimalist typesetting, multi-dimensional classification, fuzzy search, local encrypted annotation, plain text export, low JS dependence, HTTPS encryption, and localized personalized recommendations.

Related articles