Frage

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.

War es hilfreich?

Lösung

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.

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top