模板引擎的性能无法和原生的 PHP 代码相比,至于什么”模板引擎中的代码清晰”一说,看完下面再说。
替代语法
echo的替代语法
通常情况,打印一个变量
<code><?php echo $variable; ?></code>
使用替代语法,可以写成这样
<code><?=$variable?></code>
控制结构的替代语法
if
<code><?php if (): ?>// code<?php elseif (): ?>// code<?php else: ?>// code<?php endif; ?></code>
switch
<code><?php switch ():?><?php case :?>// code<?php break;?><?php case :?>// code<?php break;?><?php default:?>// code<?php endswitch;?></code>
while
<code><?php while ():?>// code<?php endwhile;?></code>
注意,没有 do…while 的替代语法。
for
<code><?php for ():?>// code<?php endfor;?></code>
foreach
<mark style="color:transparent">本%文来源gaodaimacom搞#^代%!码网@</mark>搞代gaodaima码<code><?php foreach (): ?>// code<?php endforeach; ?></code>
与模板引擎相比
Smarty 的 if
<code>{if $name == 'vip'} <h1>你好Vip</h1>{elseif $name == 'normal'} <h1>你好普通用户</h1>{else} <h1>你好游客</h1>{/if}</code>
PHP 的 if
<code><?php if ($name == 'vip'): ?> <h1>你好Vip</h1><?php elseif ($name == 'normal'): ?> <h1>你好普通用户</h1><?php else: ?> <h1>你好游客</h1><?php endif; ?></code>
两者相比,使用纯 PHP 没有想象中的那么不堪吧?况且,不用再学习任何模板技术。
‘).addClass(‘pre-numbering’).hide(); $(this).addClass(‘has-numbering’).parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('
‘).text(i)); }; $numbering.fadeIn(1700); }); }); </script>以上就介绍了使用纯PHP代替模板引擎,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。