dongtui0650 2010-12-16 03:45
浏览 56
已采纳

PhamlP将PHP呈现为注释,不执行代码

So:

I quite like using Haml in ruby projects, and was testing it out in PHP. I've been trying PhamlP because it looks like it's not dead, whereas phpHaml and pHaml haven't been updated in nearly 4 years.

Now, the problem I have is the php code that PhamlP is parsing is showing up as comments in HTML instead of executing. Here's the test file, index.php:

include_once('haml/HamlParser.php');
$haml = new HamlParser(array('ugly'=>'false'));
$page = $haml->parse('test.haml');
echo $page;

Here's the test.haml file:

!!!
- $foo = 'bar'
%h1 Foo this
.test= $foo

and here's the output I get in the browser when I view source:

<?php
require_once '/Users/Andrew/Sites/eighty-b/_app/haml/HamlHelpers.php';
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php $foo = 'bar'; ?><h1>Foo this</h1><div class="bar">This better fooacross multiple lines butstill in the bar div!</div><div class="test"><?php echo $foo; ?></div>

So, for instance, the line - $foo = 'bar' isn't being executed, it's somehow passing through to the browser as a comment.

How the heck do you fix that?

  • 写回答

4条回答 默认 最新

  • dqsvf28682 2010-12-16 04:34
    关注

    Don't know it, but the obvious workaround would be to replace the echo $page with:

     eval("?".">".$page);    // oh nooooes, eval is evil!!!!!
    

    I'd assume ->parse does just a conversion, and the output is supposed to be stored in a new .php output/template/cache file usually.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统