zoukankan      html  css  js  c++  java
  • 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文件,本人觉得不可取。
  • 相关阅读:
    std thread
    windows更新包发布地址
    How to set up logging level for Spark application in IntelliJ IDEA?
    spark 错误 How to set heap size in spark within the Eclipse environment?
    hadoop 常用命令
    windows 安装hadoop 3.2.1
    windows JAVA_HOME 路径有空格,执行软连接
    day01MyBatisPlus条件构造器(04)
    day01MyBatisPlus的CRUD 接口(03)
    day01MyBatisPlus入门(02)
  • 原文地址:https://www.cnblogs.com/dkblog/p/1981038.html
Copyright © 2011-2022 走看看