Php 显示返回和回显html标记外侧的内容
我知道echo将回显内容,return将返回内容供进一步处理。然而,我曾经说过:Php 显示返回和回显html标记外侧的内容,php,html,return,echo,Php,Html,Return,Echo,我知道echo将回显内容,return将返回内容供进一步处理。然而,我曾经说过: class Content{ protected $_html = ''; public function display_content(){ $this->_html = 'content'; } public function __toString(){ return $this->html; } } 然后我有以下几点
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>
$content=新内容();
我得到:
<p></p>
content
内容
作为页面的源代码。不管是回显还是返回,它都会显示在标签的外面
想法?我不确定第二个“内容”来自哪里,但请注意:
<?php $content->display_content();?>
不会显示
标记之间的任何内容。你应使用:
<?php echo $content->display_content();?>
(我假设Disaplay_content()是问题中的一个输入错误,而不是代码中的错误)。显示页面时是否有其他代码?““内容”不应与提供的代码一起出现。