相同字符串不相等的问题

WBOY
Release: 2016-06-23 13:42:25
Original
1673 people have browsed it

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


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


输出:

//字符tcp://77.81.105.147:7808tcp://77.81.105.147:7808//编码ASCIIASCII//长度4224//结果不等
Copy after login


回复讨论(解决方案)

var_dump($a, $b, $encode, $encodes);
贴出结果

最好是
echo base64_encode(serialize(array($a, $b, $encode, $encodes)));
贴出结果

采集的数据里有不可见的空字符吧,把ip和port trim()一下试试

最好是
echo base64_encode(serialize(array($a, $b, $encode, $encodes)));
贴出结果



结果
YTo0OntpOjA7UzoyNDoidGNwOi8vNzcuODEuMTA1LjE0Nzo3ODA4IjtpOjE7Uzo0MjoidGNwOi8vPHRkPjc3LjgxLjEwNS4xNDc8L3RkPjo8dGQ+NzgwODwvdGQ+IjtpOjI7Uzo1OiJBU0NJSSI7aTozO1M6NToiQVNDSUkiO30=
Copy after login

采集的数据里有不可见的空字符吧,把ip和port trim()一下试试


trim() 过了,还是一样的

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

原因很明显了吧?
其实你在浏览器中查看网页源代码就可以发现的

原来问题在这,我疏忽了,多谢了

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