I want to add PHP code to my web page and view it in realtime. I tried adding this in Inspect Element:

<script type="text/php">
    echo "test";
</script>

But it didn't change anything.

有帮助吗?

解决方案

PHP cannot be run in the browser like javascript.

PHP runs on the server like <?php echo "test"; ?>. PHP must be installed on the server, first, as well.

To run your PHP code in "real-time," look into ajax requests. If setup correctly, you can type PHP code on your page, have it sent to the server, and get a response from the server with the output of the PHP code without refreshing the page.

其他提示

You can't modify the DOM to add PHP to it. PHP needs to be run through the PHP engine on your server. Real time updates, per se, just aren't possible.

You can either refresh the whole page in your browser, or use Ajax to new content from the server and add it to the existing page.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top