%20和我的动态文本中的其他错误内容


%20 and other misc stuff in my dynamic text

如何从从文本文件加载的动态文本中获取html空间字符?

这就是我加载的文本在.swf:中的样子

Adaptasi%20morfologi%20adalah%20penyesuaian%2E%2E%2E%0D%0A%0D%0A=&onLoad=%5Btype%20Function%5D

这是我的行动脚本:

var select_obj:LoadVars = new LoadVars(); 
select_obj.onLoad = function(success:Boolean) { 
    if (success) { 
        isi.text = select_obj;
        trace (select_obj);
    } else { 
      trace('error...');
    } 
}; 
filepath = "http://localhost/adaptasi/";
select_obj.sendAndLoad(filepath + "morfologi.php", select_obj, "GET");

这是我的PHP脚本:

<?php
mysql_pconnect ("localhost", "root", "");
mysql_select_db ("adaptasi");
$qResult = mysql_query ("SELECT isi FROM materi WHERE id = 1");
$nRows = mysql_num_rows($qResult);
$rString ="";
for ($i=0; $i< $nRows; $i++){
    $row = mysql_fetch_array($qResult);
    $rString .= $row['isi'];
}
echo $rString;
?>

要获得脚本发送的值,您应该将它们作为URL编码的查询字符串返回,其中包含如下名称/值对:

message=hello&from=user1&to=user2

可以通过您的PHP脚本返回:

<?php
    echo "message=hello&from=user1&to=user2";
?>

LoadVars对象将自动为您解码(解析)该变量字符串作为LoadVars对象的属性:

var result:LoadVars = new LoadVars(); 
    result.onLoad = function(success:Boolean) {
        if (success) {
            trace(result.message);  // gives : hello
            trace(result.from);     // gives : user1
            trace(result.to);       // gives : user2
            trace(result);          // gives : to=user2&from=user1&message=hello&onLoad=%5Btype%20Function%5D
        } else {
            trace('error !');
        }
    };
    result.sendAndLoad(filepath, result);

希望这能有所帮助。

使用urldecode()函数:

<?PHP
$string = "Adaptasi%20morfologi%20adalah%20penyesuaian%2E%2E%2E%0D%0A%0D%0A=&onLoad=%5Btype%20Function%5D";
//$string = $_GET['variable'];
$rString = urldecode($string);
echo $rString;

我想擦除%20,%2E%2E%2E%,等等。

为此,您可以尝试decodeURIComponent或仅decodeURI。阅读该手册以了解差异(但就您目前的结果而言,这两种方法中的任何一种都是好的)。

代码示例:

var result:LoadVars = new LoadVars(); 
var filepath:String;
filepath = "localhost/adaptasi/"; 
result.sendAndLoad(filepath + "morfologi.php", result, "GET");
result.onLoad = function(success:Boolean) 
{ 
    if ( success ) 
    {   
        text_morfo.text = result; 
        text_morfo = decodeURIComponent( text_morfo );
        trace("success route : "); trace( text_morfo );   
    } 
    else { trace("error in result..."); } 
}

我也不知道你的AS&稍后将添加PHP代码,因此如果您需要快速测试工具,可以尝试此链接。只需将跟踪结果放入底部框中,然后选择选项(如unescapedecodeURI等)。这将快速帮助您了解在AS代码中最好使用哪个命令。