Home Backend Development PHP Tutorial Usage examples of xml format in php files

Usage examples of xml format in php files

Oct 12, 2018 pm 03:02 PM
php file

The content of this article is about the usage examples of xml format in php files. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

The xml file was used in the process of writing a questionnaire. If you want to know more, you can simply learn through the following link: http://www.php.cn/course/28.html

Tools used: phpstudy notepad (using utf-8 encoding without BOM)

The problems that arise are as follows: The initial code is as follows: I want to ask how many people are going to go out to Changsha to play,
<?php
header(&#39;Content-Type: text/xml&#39;);
$xmlstr="<?xml version=\"1.0\" encoding=\"utf-8\"?> 
<movies>
<movie>
<title>旅游的人数</title>
<id>1</id>
<count>350</count>
<content>长沙</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>2</id>
<count>47</count>
<content>张家界</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>3</id>
<count>118</count>
<content>上海</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>4</id>
<count>80</count>
<content>南京</content>
</movie>
</movies>
";
$xml = simplexml_load_string($xmlstr);
$count0 = $xml->movie[0]->count;
echo $count0;
?>
Copy after login

Firefox On browser:

XML parsing error: Syntax error
Location: http://localhost:8080/diaocha/2.php
Line 1, Column 1: 350

Error on 360 browser:

This page contains the following errors:

error on line 1 at column 1: Document is empty

Below is a rendering of the page up to the first error

What needs to be corrected is:

Remove the first sentence: header('Content-Type: text/xml');. Get 350

2. If you need to view the xml format

The code is as follows:

<?php
header(&#39;Content-Type: text/xml&#39;);
$xmlstr="<?xml version=\"1.0\" encoding=\"utf-8\"?> 
<movies>
<movie>
<title>旅游的人数</title>
<id>1</id>
<count>350</count>
<content>长沙</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>2</id>
<count>47</count>
<content>张家界</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>3</id>
<count>118</count>
<content>上海</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>4</id>
<count>80</count>
<content>南京</content>
</movie>
</movies>
";
Copy after login

The result can be obtained:

This XML file does not appear to have any style information associated with it. The document tree is shown below.

<movies>
<movie>
<title>旅游的人数</title>
<id>1</id>
<count>350</count>
<content>长沙</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>2</id>
<count>47</count>
<content>张家界</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>3</id>
<count>118</count>
<content>上海</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>4</id>
<count>80</count>
<content>南京</content>
</movie>
</movies>
";
Copy after login

The sentence above can be ignored: there is no such sentence on the IE browser, so it is just because Other browser compatibility only.

The above is the detailed content of Usage examples of xml format in php files. For more information, please follow other related articles on the PHP Chinese website!

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

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

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)

How to open php files on mobile phone How to open php files on mobile phone Nov 13, 2023 am 11:08 AM

To open a php file on a mobile phone, you need to set up a server environment that can run php on the mobile phone and upload the php file to the server. Then, enter the IP address or domain name of the server, plus the path to the php file, into the browser on your phone to open the php file and view its contents.

How to deal with case errors in PHP file paths and generate corresponding error messages How to deal with case errors in PHP file paths and generate corresponding error messages Aug 08, 2023 pm 09:45 PM

How to deal with case errors in PHP file paths and generate corresponding error messages. In the process of developing PHP programs, we often encounter the problem of case errors in file paths. Since Windows and Linux systems handle file path case differently, when the program passes the test using the Windows system in the development environment, it may cause path errors when it is deployed to the Linux server. In order to solve this problem, we can use some methods to deal with the large file path

How to open php file How to open php file Sep 01, 2023 am 11:53 AM

Steps to open a php file: 1. Select a text editor; 2. Create a new file in the selected text editor and save it as a .php file; 3. Write PHP code in the created PHP file; 4. To run PHP files on your local computer, you need to set up a server environment; 5. After installing the server environment, you need to put the PHP files into the server directory; 6. Once you put the PHP files into the server directory, you can browse server to run it.

Several aspects of content can be included in the .php file Several aspects of content can be included in the .php file Mar 06, 2023 pm 05:32 PM

What can be included in the php file: 1. The starting tag "<?php" and the ending tag "?>", all PHP code must be written inside this pair of tags; 2. The semicolon ";" is a PHP statement The delimiter also represents the instruction for code execution; 3. Comments, including single-line comments "//", multi-line comments "/* */", and Shell comments "#"; 4. Line breaks, which can Enhance the readability of the code; 5. Code segments (such as functions, etc.).

how to open php file how to open php file Jan 24, 2024 pm 04:12 PM

Tools for opening php files: 1. Notepad++; 2. Sublime Text; 3. Visual Studio Code; 4. Eclipse; 5. XAMPP. Detailed introduction: 1. Notepad++, which is a free text editor that supports multiple programming languages, including PHP. It has functions such as syntax highlighting and code folding, making it easier to read and edit PHP code; 2. Sublime Text , a powerful text editor and more.

What code can a PHP file contain? What code can a PHP file contain? Aug 01, 2023 pm 01:34 PM

PHP files can contain code: 1. PHP code, used to complete various server-side tasks; 2. HTML code, used to define the structure and layout of the web page; 3. CSS code, used to define the style of the web page; 4. JavaScript Code, used to implement various dynamic interaction functions in web pages; 5. SQL code, used to operate the database; 6. The file contains code, which can modularize the code; 7. Third-party libraries and frameworks, which can be quickly constructed Feature-rich application.

What are the prerequisites for running PHP programs? What are the prerequisites for running PHP programs? Mar 26, 2024 pm 03:45 PM

Title: Prerequisites and examples for running PHP programs. PHP is a scripting language widely used in web development. Many websites use PHP to run their dynamic content. To successfully run a PHP program, some prerequisites must be met. The following will introduce the prerequisites for running PHP programs and provide specific code examples. Server environment First of all, PHP programs need to run normally in a server environment that supports the PHP language. The most common server environment is an Apache server and requires a PHP interpreter to be installed

How to handle PHP file encoding errors and generate corresponding error messages How to handle PHP file encoding errors and generate corresponding error messages Aug 06, 2023 pm 02:09 PM

How to handle PHP file encoding errors and generate corresponding error messages. When developing PHP applications, file encoding errors are often encountered. These errors may cause the program to fail to run properly or display garbled code in front of the user. In order to better handle these errors and generate corresponding error messages, we can take some common solutions. Determine the file encoding First, we need to determine the encoding format of the file. Common encoding formats include UTF-8, GBK, etc. You can view it through the "Save As" function of your text editor.

See all articles