2017-06-19 106 views
0

由于我在处理大代码,我想知道是否有任何可能性更容易用PHP代码替换HTML,以便例如<?php $HelloWorld ?>在文档中会变成类似--HelloWorld--的东西?或者例如循环会去从:用PHP代替HTML

<?php 
for ($x = 0; $x <= 10; $x++) { 
    echo "The number is: $x <br>"; 
} 
?> 

为了简化管柱像

-(10)-{The number is: $x <br>}- 
+0

有许多可以做这样的事情的模板库。 – Barmar

+0

也许看看Smarty? http://www.smarty.net/ – hRdCoder

+1

https://twig.sensiolabs.org/,http://www.smarty.net/ – circusdei

回答

3

是什么,你正在寻找一个模板引擎。

许多如果不是所有主要的PHP框架都有一个模板引擎,可以使用这种模板。例如

Laravel例如使用称为刀片的模板引擎,它使您能够写入刀片服务器语法。

The number is {$x} 

或者

@foreach ($users as $user) 
{$user->name} <br> 
@endforeach 

或者

@if(true) 
Do this 
@else 
Else do that 
@endif 

希望这有助于