How to encapsulate app in php

藏色散人
Release: 2023-03-14 08:16:01
Original
2718 people have browsed it

How to encapsulate app in php: 1. Create json.php file and demo.php file; 2. Use array to represent JSON format data in php; 3. Enclose the array into JSON data.

How to encapsulate app in php

The operating environment of this article: windows7 system, PHP7.4 version, DELL G3 computer

Use php to encapsulate the APP interface

php encapsulation APP interface

Let’s first introduce the Json encapsulation method

If the json_encode function passes Chinese, the output will be garbled. , I think it is necessary to make an explanation for this problem:

In fact, json_encode is not garbled for Chinese, but json_encode will convert Chinese into unicode encoding, so the output will be this encoding, but it does not affect our use. We After json_decode, it will be a normal value, but if you want to output json_encode in Chinese, there is actually a way, as follows:

echo urldecode(json_encode(urlencode("JSON Chinese output solution")) ; Many only have this function;

But in terms of readability, XML looks more intuitive, while Json looks messy and time-consuming;

The above is Json below Let’s get an XML one!

Method: PHP generates XML data;


How to generate XML data?

The following two methods can be achieved--> 1. Assemble into an XML string 2. Use system classes such as: DomDocument, XMLWriter, SimpleXML

Go to the Demo directly first!

<?php  
  
//服务端 json.php  
//php中用数组表示JSON格式数据  
header("Content-type:text/html;charset=utf-8");  
$arr = array(    
    &#39;code&#39; => 200,  
    &#39;message&#39; => &#39;数据返回成功&#39;,  
    &#39;data&#39; => array(    
        &#39;name&#39; =>&#39;bawei&#39;,    
        &#39;email&#39; =>&#39;www.bawei@qq,com&#39;,    
    ),  
);   
echo json_encode($arr); //将数组封闭成JSON数据 主要函数json_encode;  
?>
Copy after login


Recommended learning: "
PHP Video Tutorial

"

The above is the detailed content of How to encapsulate app in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template