Home  >  Article  >  Backend Development  >  Example of php code execution in html file

Example of php code execution in html file

不言
不言Original
2018-09-01 09:32:122134browse

What this article brings to you is an example of how PHP code is executed in an HTML file. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

What we introduce here is to execute it through js. As for modifying the configuration file on the server, we will not discuss it 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.
test.php contains this:

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

Related recommendations:

How to call Python to implement multi-threading (graphics and text)

phpHow to get the mobile phone number and IP address of the mobile phone (code example)

The above is the detailed content of Example of php code execution in html file. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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