内容显示html标签的一面用于返回和回显

时间:2013-01-30 22:49:02

标签: php html return echo

我知道echo将回显内容并返回将返回内容以供进一步处理。但是,我说过功能:

class Content{

    protected $_html = '';

    public function display_content(){
        $this->_html = 'content';
    }

    public function __toString(){
        return $this->html;
    }
}

然后我有以下内容:

$content = new Content();
<p><?php $content->disaply_content(); ?></p>

我明白了:

<p></p>
content

作为页面的源代码。如果我回声或只是返回并不重要,无论哪种方式它都显示在标签旁边。

想法?

1 个答案:

答案 0 :(得分:1)

我不确定第二个“内容”的来源,但请注意:

<?php $content->display_content();?>

不会在<p>标记之间显示任何内容。你应该使用:

<?php echo $content->display_content();?>

(我假设disaply_content()在问题中是一个拼写错误,而不是在代码中。)