HTML 将括号内的代码视为 PHP 代码
我完全用 PHP 构建我的网站。我正在努力使其尽可能灵活。
我看到有一些用PHP制作的软件能够获取HTML页面,并且在显示它之前,PHP代码将括号{PHP Code}
内的代码识别为PHP代码,运行它并然后才显示最后一页。
<h1>Hi My Name is {echo $name}</h1>
我怎样才能达到同样的效果?我知道有Smarty Code。但我不想学习Smarty,我只是想知道如何使用PHP检查HTML页面,在显示页面之前找到PHP的每个括号和威胁..?
你能指点我一个地方吗?
I am building my website completely in PHP. I am trying to make it as much flexible as possible.
I have seen there are some softwares made in PHP that are able to get a HTML page, and before showing it, the PHP code recognizes the code inside brackets {PHP Code}
as PHP code, runs it and only then shows the final page.
<h1>Hi My Name is {echo $name}</h1>
How can I achieve the same? I know there is Smarty Code. But I do not want to learn Smarty, I just want to know how to check a HTML page with PHP, find every bracket and threat that as PHP before showing the page..?
Can you point me somewhere?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您在寻找 PHP 的基本语法吗?
如果您启用
short_open_tags
(通常默认情况下启用),这将起作用:否则,这将始终起作用:
PHP已经是一种模板语言 - 通常不需要添加另一个 /em> 其上的模板层。
Are you looking for PHP's basic syntax?
If you enable
short_open_tags
(it usually is enabled by default), this will work:otherwise, this will always work:
PHP is already a templating language - there often is no need to add another layer of templating on top of it.
事实上,您不需要
您的模板文件在各方面都将表现为本机 PHP 文件。
因此,绝对没有[合乎逻辑]的理由去选择这样一个奇怪的解决方案而不是原生 PHP。
In fact, you don't
Your template files would behave as native PHP files in every way.
So, there is asolutely no [logical] reason to prefer such a strange solution over native PHP.
使用 echo 语句的 php 标签。
use the php tags for the echo statement.
好吧,只需将 apache 指向 index.php,其中 包含 phtml 模板即可。使用
而不是
{ }
。Well, just point apache to index.php which includes phtml templates into itself. Use
<?php ?>
instead of{ }
.