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!

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

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答