• flash和php的url编码传换


    那天请教HBr搞flash画板,出现了getURL传出的变量里有特殊字符在php接变量输出出现丢失.比如:输出一个xml文件里带引号,到php里引号不见了.
    Code:
    <lines><line x1="297" x2="299" y1="292.95" y2="293.95" time="2563" /><line x1="299" x2="367.95" y1="293.95" y2="311.95" time="2720" /></lines>
    </lines>

    变成:
    Code:
    <lines><line x1=297 x2=299 y1=292.95 y2=293.95 time=2563 /><line x1=299 x2=367.95 y1=293.95 y2=311.95 time=2720 /></lines>

    做法1:
    只需要在flash里用escape把lines.toString()字符串转换为以URL编码格式进行编码,将所有非字母数字的字符都转义为十六进制序列字符串。
    Code:

    var lines = new XML("<?xml version=\"1.0\" standalone=\"no\"?><lines></lines>");
    ......
    save.onRelease=function(){
    contents=escape(lines.toString());
    trace(contents);
    getURL("http://localhost/php/myapp/flash/huaban/savefile.php?filename="+filename+"&contents="+contents)
    }

    然后在php里用stripslashes去掉反斜线(因为php自动将传过来的十六进制字符转成了ASCII字符并加入了反斜线,所以我们只要去掉就行)
    Code:

    <?php
    $contents=$_GET[contents];
    header("content-type:text/xml");
    header("Expires:-1");
    echo stripslashes($contents);
    ?>

    做法2:
    在flash里尽量不输出有特殊字符的字符串,比如本例可在flash里改造xml成如下格式的,然后在php里加上
    Code:
    echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
    输出xml声明。
    Code:

    <lines><line><x1>297</x1><y1>275</y1><x2>298</x2><y2>275</y2><time>2330</time></line></lines>
    <lines><line><x1>297</x1><y1>275</y1><x2>298</x2><y2>275</y2><time>2330</time></line><line><x1>298</x1><y1>275</y1><x2>299</x2><y2>275</y2><time>2395</time></line></lines>
    <lines><line><x1>297</x1><y1>275</y1><x2>298</x2><y2>275</y2><time>2330</time></line><line><x1>298</x1><y1>275</y1><x2>299</x2><y2>275</y2><time>2395</time></line><line><x1>299</x1><y1>275</y1><x2>300</x2><y2>275</y2><time>2491</time></line></lines>

    不过这种格式会大大加大xml文件,本人觉得不可取。
  • 相关阅读:
    实验 4:Open vSwitch 实验——Mininet 中使用 OVS 命令
    实验 3:Mininet 实验——测量路径的损耗率
    软工第一次作业
    实验2:Mininet实验——拓扑的命令脚本生成
    实验 1:Mininet 源码安装和可视化拓扑工具
    AU降噪处理
    软件测试,Homework3
    软件测试,Lab1
    软件测试,Homework2
    node.js,同时访问出错,Can't set headers after they are sent
  • 原文地址:https://www.cnblogs.com/dkblog/p/1981038.html
Copyright © 2020-2023  润新知