Home >Backend Development >PHP Problem >What are the advantages of php interacting with web pages?
What are the advantages of php interacting with web pages?
The advantages of php interacting with web pages are:
1. PHP can directly output HTML, CSS, and JavaScript, and can write code mixed with HTML.
2. PHP can directly return json, and js can be used without additional operations.
header('Content-Type:application/json; charset=utf-8'); $arr = array('a'=>1,'b'=>2); exit(json_encode($arr));
Note: If the value of json_encode is output directly without adding a header, a string will be returned. It is not an object. On the js side, you need to eval('(' data ')') first to convert it into an object, and then get the value.
Supplement:
a) Return xml data:
header('Content-Type:text/xml; charset=utf-8'); exit($xml);
b) Return jsonp data:
$arr = array('a'=>1, 'b'=>2, 'c'=>3); $json = json_encode($arr); $callback = $_GET['callback']; exit($callback."($json)"); //注意callback是js传过来的参数名称
3. PHP is easy to use and can be used very conveniently Add, delete, modify and check the database. It is developed quickly and is a language specifically designed for making websites.
4. Strong cross-platform capability. Since PHP is a script that runs on the server side, it can run under UNIX, LINUX, WINDOWS, and Mac OS.
5. High efficiency PHP consumes very few system resources.
For more PHP related knowledge, please visit PHP Chinese website!
The above is the detailed content of What are the advantages of php interacting with web pages?. For more information, please follow other related articles on the PHP Chinese website!