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)

烟雨青岚
Release: 2023-04-08 20:54:01
forward
6803 people have browsed it

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>
Copy after login

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;
?>
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template