" and " ” to execute."/> " and " ” to execute.">

Home >Backend Development >PHP Tutorial >How to execute php code in html file (detailed explanation)

How to execute php code in html file (detailed explanation)

烟雨青岚
烟雨青岚forward
2020-06-12 09:02:486833browse

How to execute php code in html file (detailed explanation)

How to execute php code in html file

What we introduce here is to execute it through js, as for modification The configuration files on the server will not be discussed here. Here we just provide an idea. After all, it is said on the Internet that php functions cannot be executed in HTML, let alone using frameworks.

<script src="test.php"></script>
<script>document.write(a);</script>

The above is the front-end processing part.

This is what is written in test.php:

<?php
//$a作为php变量,上面可以写你的php逻辑,处理的结果定义为你想要调用的结果即可;
//但是一般不建议用这样的方式去在html调用php变量,这里只是提供一个解决的思路而已.
//用这个去解决实际问题是不合理的,当个兴趣了解一下就可以了。
echo "var a=".$a;
?>

The above is how the php code is executed in the html file. Have you learned it?

This article is reproduced from: https://blog.csdn.net/zhou120189162/article/details/82256449

Recommended tutorial: "php tutorial"

The above is the detailed content of How to execute php code in html file (detailed explanation). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete