首頁 >後端開發 >php教程 > php形成json语句,多出前面一句,如何去掉

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

WBOY
WBOY原創
2016-06-13 12:39:40990瀏覽

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
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn