Home  >  Article  >  Backend Development  >  php形成json语句,多出前面一句,如何去掉

php形成json语句,多出前面一句,如何去掉

WBOY
WBOYOriginal
2016-06-13 11:32:28750browse

php形成json语句,多出前面一句,怎么去掉!
php源码

<br /><br /><?php<br />	//session start<br />	session_start();<br />	include "./mobile/sql.php";<br />	$con = mysql_connect($domain,$usrnm,$password);<br />	mysql_select_db($usrnm) or die('Could not select database'); <br />	mysql_query("set character set 'utf8'");<br />	$page = $_GET['page'];<br />	<br />	<br />	if(!$con){<br />		<br />		echo("can not connect");<br />	}<br />	else{<br />		//1.登陆授权<br />		if($page=='login'){<br />			//1.读取用户数据,并进行匹配<br />			$usrname = $_GET['usrnm'];<br />			$pas			= $_GET['pas'];<br />			<br />			//2.检索数据库<br />			$sql = "select * from mb_usr";<br />			$result = mysql_query($sql) or die('Query failed: ' . mysql_error());<br /><br />			while( $row = mysql_fetch_array($result) ){<br />				<br /> 			   	if(($row['usrid']==$usrname || $row['mail']==$usrname || $row['phoneno']==$usrname) && $row['pas']==$pas){<br />					//3.分配session值 保留登陆时限<br />					$_SESSION[$usrname] = $usrname;<br />					<br />					//4.构建login的json格式<br />					$jsonArr = Array('logintype'=>$row['usrtype'],'sessionid'=>$usrname,'usrnm'=>$row['usrnm'],'usrid'=>$row['usrid']);<br />					<br />					echo json_encode($jsonArr);<br />					<br />					break;<br />					}<br />					else{<br />						echo '{"logintype":"-1"}';<br />						}<br />				}<br />			}<br />			<br />	}<br /><br /><br />?><br /><br />



浏览器解析为
<br /><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />{"logintype":"0","sessionid":"0","usrnm":"mjc","usrid":"0"}<br /><br />



怎么将前一行去掉!

JSON php PHP
Statement:
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