Home > Backend Development > PHP Tutorial > PHP中一个文件调用另一个文件类的方法,然后输出出现乱码,求解!该如何处理

PHP中一个文件调用另一个文件类的方法,然后输出出现乱码,求解!该如何处理

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:47:38
Original
1080 people have browsed it

PHP中一个文件调用另一个文件类的方法,然后输出出现乱码,求解!
tt.php文件

<?php<br />class CTest<br />{<br />	private $m_str;<br />	public function SetData($data)<br />	{<br />		$m_str=$data;<br />	}<br />	public function GetData()<br />	{<br />		return $m_str;<br />	}<br />}<br />	<br />?>
Copy after login



文件test.php
<?php<br />	echo "Begin test <br>"; // 正常显示<br />	require_once './tt.php';<br />	$p=new CTest();<br />	$p->SetData("Could you get this data?");<br />	$str=$p->GetData();<br />	echo $str; // 无法正常显示<br />?>
Copy after login


------
在浏览器中显示test.php执行结果
Begin test




------解决方案--------------------
class CTest<br />{<br />    private $m_str;<br />    public function SetData($data)<br />    {<br />        $this->m_str=$data;<br />    }<br />    public function GetData()<br />    {<br />        return $this->m_str;<br />    }<br />}<br />
Copy after login

------解决方案--------------------
请检查$data的编码与页面编码是否一致。
------解决方案--------------------
设下页面的编码

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template