Solution to the garbled value passed from flash to php: 1. View all Flash codes; 2. Add "header('Content-Type:text/html;charset=utf-8' at the beginning of PHP );" That's it.
The operating environment of this article: Windows7 system, PHP7.1 version, Dell G3 computer
Specific problem description:
The communication between PHP and Flash is all garbled.
No more nonsense, let’s go directly to the code
The complete code of PHP is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>test</title> </head> <body> <?PHP $sending="这是返回的数据"; echo "$sending"; ?> </body> </html>
All codes of Flash As follows:
import flash.events.MouseEvent; import flash.net.URLRequest; import flash.net.URLLoader; import flash.events.Event; var url:String = "http://localhost/testing.php"; var req:URLRequest=new URLRequest(); bt.addEventListener(MouseEvent.CLICK,clickHd); function clickHd(e:MouseEvent) { req.url = url; req.method = URLRequestMethod.POST; var loaded:URLLoader=new URLLoader(); loaded.dataFormat = URLLoaderDataFormat.VARIABLES; loaded.addEventListener(Event.COMPLETE,completeHd); try { msg.text = "正在请求数据。。。"; } catch (err:Error) { msg.text = "错误,稍后再试"; } loaded.load(req); } function completeHd(e:Event) { msg.text = e.target.data; navigateToURL(req); }
There is a msg dynamic text box and bt button in flash
Solution:
Add ## at the beginning of PHP #
<?php header('Content-Type:text/html;charset=utf-8'); ?>
PHP Video Tutorial"
The above is the detailed content of What to do if the value passed from flash to php is garbled?. For more information, please follow other related articles on the PHP Chinese website!