当前位置:Gxlcms > PHP教程 > 相同字符串不相等的有关问题

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

时间:2021-07-01 10:21:17 帮助过:11人阅读

相同字符串不相等的问题
本帖最后由 qq_24844315 于 2014-12-31 12:16:38 编辑

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




$a="tcp://".$ip.":".$duankou;
$b="tcp://77.81.105.147:7808";

echo $a."
";
echo $b."
";

$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."
";
echo $encodes."
";

$changdu1= strlen($a);
$changdu2= strlen($b);

echo $changdu1."
";

echo $changdu2;
if($a==$b)
{

echo "相等";

}

else
{
echo "不等";
}




输出:


//字符
tcp://77.81.105.147:7808
tcp://77.81.105.147:7808

//编码
ASCII
ASCII

//长度
42
24

//结果
不等


------解决思路----------------------
$s = 'YTo0OntpOjA7UzoyNDoidGNwOi8vNzcuODEuMTA1LjE0Nzo3ODA4IjtpOjE7Uzo0MjoidGNwOi8vPHRkPjc3LjgxLjEwNS4xNDc8L3RkPjo8dGQ+NzgwODwvdGQ+IjtpOjI7Uzo1OiJBU0NJSSI7aTozO1M6NToiQVNDSUkiO30=';

$a = unserialize(base64_decode($s));
var_dump($a);
array(4) {
[0]=>
string(24) "tcp://77.81.105.147:7808"
[1]=>
string(42) "tcp://77.81.105.147:7808"
[2]=>
string(5) "ASCII"
[3]=>
string(5) "ASCII"
}


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

人气教程排行