2011-04-11 109 views
-2
<?php if (!empty(cutstr($node->content,300))) : ?> 
     <div class="pr_teaser"> 
     <?php echo cutstr($node->content,300); ?> 
     </div> 
    <?php endif; ?> 

代码有什么问题? cutstr功能没问题。我的IDE对此行提醒<?php if (!empty(cutstr($node->content,300))) : ?>是错误的?但我找不到错误。代码有什么问题?

+7

是什么让你觉得有什么错呢? (即,你期望输出什么,你会得到什么输出?) – Quentin 2011-04-11 08:22:54

+0

绝对错误的是你没有使用'htmlspecialchars()'来转义输出。 – Tomalak 2011-04-11 08:25:29

+0

阅读文档有助于:http://php.net/manual/en/function.empty.php。请注意该笔记。 – 2011-04-11 08:26:50

回答

4

empty()仅检查变量为 其他任何情况都会导致解析 错误。换句话说,以下 将不起作用:空(trim($ name))。

http://php.net/manual/en/function.empty.php

你需要做这样的事情:

<?php $value=cutstr($node->content,300); if (!empty($value)) : ?> 
    <div class="pr_teaser"> 
    <?php echo $value; ?> 
    </div> 
<?php endif; ?> 
+0

明白了。谢谢 – zhuanzhou 2011-04-11 08:26:52