如何获得html段落值的php变量


How to get html paragraph value to a php variable?

我试图使用PHP符合框获得用户批准之前删除数据。因此,我使用下面的代码来显示一致性框,它工作得很好。

但是现在我在检索用户响应时遇到了麻烦。现在它被分配给一个段落(称为demo),但我希望它分配给一个php变量($user_res)。我不知道该怎么做。

 <?php
  echo '<p id="demo" ></p>';
    echo '<script>';
     echo 'var txt;';
     echo ' var r = confirm("Press a button!");';
     echo 'if (r == true) {';
     echo 'txt = "You pressed OK!";';
     echo '} else {';
     echo 'txt = "You pressed Cancel!";';
     echo '}';
     echo 'document.getElementById("demo").innerHTML = txt;';
    echo '</script>';
   ?>

在PHP文件中使用HTML并为$key处理插入PHP标签

<html>
<?php $key="demo" ?>
    <p id="demo" ></p>
 <script>;
     var txt;
     var r = confirm("Press a button!");
     if (r == true) {
     txt = "You pressed OK!";
     } else {
     txt = "You pressed Cancel!";
     }
     document.getElementById("<?php $key ?>").innerHTML = txt;
    </script>
</html>

谢谢你。这很有帮助。我发现了这个,它也在工作。

 <button id="btnfun1" name="btnfun1" onClick='location.href="?button1=1"' >OK</button>
        <button id="btnfun2" name="btnfun2" onClick='location.href="?button2=1"' >Cancel</button>
 <?php
   if($_GET['button1']){fun1();}
     if($_GET['button2']){fun2();}
     function fun1()
     {
       echo "fun1";
     }
     function fun2()
     {
       echo "fun 2";
     }