所以我有这个代码:
$template_file = 'template.tpl.php';
ob_start(); // Start output buffering
include "./$template_file"; // Include the template file
$contents = ob_get_contents(); // Get the contents of the buffer
ob_end_clean(); // End buffering and discard
return $contents;
这就是template.tpl.php的样子:
<?=translate_string('A message to display to user')?>
然而,当我检查$contents的内容时,它不是显示'A message to display to user'
,而是显示<?=translate_string('A message to display to user')?>
。。。即,它显示整个PHP代码,而不是执行PHP代码,并简单地返回执行代码的输出。。。
你知道是什么原因造成的吗?
我正在使用Drupal 6
编辑
看起来short_open_tag设置为On…还有其他可能吗?
如果我仍然可以使用<?=
表示法而不使用<?php
等,那就太好了……因为它在中使用得很普遍
进一步更新
看起来jszobody不再有进一步的贡献,如果除了short_open_tag设置之外,其他人知道可能导致这种情况的原因,请随时回答
thx到jszobody的short_open_tag贡献
您在模板代码中使用了PHP短标记。如果服务器上没有启用这些功能,PHP就不会对其进行解析,而是将其视为纯文本。
请参见此处:http://www.php.net/manual/en/ini.core.php#ini.short-开放标签
我会把你的模板改成这样:
<?php echo translate_string('A message to display to user'); ?>