首页 > 解决方案 > 带有 Javascript 弹出窗口的字符串中的 PHP 变量

问题描述

在 /var/www/html/msg.txt 中只有一个词“测试”。

有人可以告诉我为什么这不起作用吗?

 echo "<script>alert('$tes');</script>";

完整的php代码:

<?php
    $ma="Test";
    $tes = file_get_contents("/var/www/html/msg.txt");

    echo "$tes"; //works

    echo "<script>alert('$ma');  //works
    </script>";

//but if this

         echo "<script>alert('$tes'); // doesn't work!!!! Why?
         </script>";
    ?>

我该怎么做?

标签: javascriptphpvariablespopup

解决方案


问题在于您的 file_get_contents。可能您设置的路径不正确,或者您尝试访问的文件没有正确的权限


推荐阅读