Home  >  Article  >  Backend Development  >  相同字符串不相等的有关问题

相同字符串不相等的有关问题

WBOY
WBOYOriginal
2016-06-13 12:12:461249browse

相同字符串不相等的问题

本帖最后由 qq_24844315 于 2014-12-31 12:16:38 编辑 说明:从一个页面采集ip和端口,$ip和$duankou是采集的,然后发现不能用,但是手动输入可以用,对比了
两个字符串,发现长度不相同,但是编码相同,请教这该怎么办
现在是 $b 是有效的,$a无效,


<br /><br />$a="tcp://".$ip.":".$duankou;<br />$b="tcp://77.81.105.147:7808";<br /><br />echo $a."<br>";<br />echo $b."<br>";<br /><br /> 	 $encode = mb_detect_encoding($a, array("ASCII","UTF-8","GB2312","GBK","BIG5")); <br />	  $encodes= mb_detect_encoding($b, array("ASCII","UTF-8","GB2312","GBK","BIG5")); <br />	<br /><br />		   echo $encode."<br>";<br />		echo $encodes."<br>";<br /><br />	$changdu1=	strlen($a);<br />	$changdu2=	strlen($b);<br />	<br />	echo $changdu1."<br>";<br /><br />	echo $changdu2;<br />if($a==$b)<br />{<br /><br />echo "相等";<br /><br />}<br /><br />else<br />{<br />echo "不等";<br />}<br /><br /><br />


输出:

<br />//字符<br />tcp://77.81.105.147:7808<br />tcp://77.81.105.147:7808<br /><br />//编码<br />ASCII<br />ASCII<br /><br />//长度<br />42<br />24<br /><br />//结果<br />不等<br /><br />

------解决思路----------------------
$s = 'YTo0OntpOjA7UzoyNDoidGNwOi8vNzcuODEuMTA1LjE0Nzo3ODA4IjtpOjE7Uzo0MjoidGNwOi8vPHRkPjc3LjgxLjEwNS4xNDc8L3RkPjo8dGQ+NzgwODwvdGQ+IjtpOjI7Uzo1OiJBU0NJSSI7aTozO1M6NToiQVNDSUkiO30=';<br /><br />$a = unserialize(base64_decode($s));<br />var_dump($a);
array(4) {<br />  [0]=><br />  string(24) "tcp://77.81.105.147:7808"<br />  [1]=><br />  string(42) "tcp://<td>77.81.105.147</td>:<td>7808</td>"<br />  [2]=><br />  string(5) "ASCII"<br />  [3]=><br />  string(5) "ASCII"<br />}<br /><br />

原因很明显了吧?
其实你在浏览器中查看网页源代码就可以发现的
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