質問

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