douliwang6896 2017-03-14 18:47
浏览 32
已采纳

你能帮我理解为什么这是我的php函数的输出吗?

I have this function:

function dec($dec)
{
    $ans="";
    for($x=0; $x<strlen($dec);$x++)
    {
        $tempAscii = ord(substr($dec,$x,1)) - ($x+1)*2; //((int)dec[x] - (x+1)*2)
        while ($tempAscii <0) $tempAscii+=256;
        echo $tempAscii,", ";
        $ans = $ans . chr($tempAscii); 
    }
    return $ans;
}
echo "dec, ", dec($_GET['word']);

for example, those dec results are just fine:

input: as output: _o middle output: 95, 111
input: SHA256 output: QD;*+* middle output:  81, 68, 59, 42, 43, 42

But when I'm trying this input, I got something strange:

input: $@SHA256*!# output: " middle output: 34, 60, 77, 64, 55, 38, 39, 38, 24, 13, 13

I'm not sure if the reason I get this output is because I'm doing a mistake in my function, or there is other reason. Why I got " as the last result? thanks.

EDIT: I'm using firefox to see the results. EDIT: It seems that <is the problem. It seems that firefox take this as "smaller then"... How can I change it to be just > char without any meaning?

  • 写回答

1条回答 默认 最新

  • dongshao1873 2017-03-14 20:13
    关注

    Here is the solution: as @kyeiti mention before, the browser trying to interpret this string as code.

    according to this question I solved this by using the command htmlspecialchars. So now my code is:

    echo htmlspecialchars(enc($_GET['word']));
    

    many thanks!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作