PHP:无效的字符串不允许我正确比较它
由于某种原因,在数组内生成了一个非常奇怪的字符串,我不知道如何处理它...我正在获取该字符串并使用以下代码输出它:
$server = '{imap.gmail.com:993/ssl}';
$connection = imap_open($server, 'myuser', 'mypass');
$count = imap_num_msg($connection);
$header = imap_headerinfo($connection, $i);
for($i = 1; $i <= $count; $i++) {
$from = $header['fromaddress'];
var_dump($from);
}
这是我从 var_dump 得到的结果:
string(39) "Support Testing1"
这怎么可能?有什么方法可以将其转换为正确的字符串(我的意思是,具有正确的长度?)
这会影响我的代码,因为 now:
echo ('Support Testing1' == $from)
给了我 false,而它应该是 true。有什么想法吗?谢谢!
更新:修剪也不起作用。
A really weird string is being produced inside an array for some reason, and I don't know how to treat it... I am getting the string and outputting it with the following code:
$server = '{imap.gmail.com:993/ssl}';
$connection = imap_open($server, 'myuser', 'mypass');
$count = imap_num_msg($connection);
$header = imap_headerinfo($connection, $i);
for($i = 1; $i <= $count; $i++) {
$from = $header['fromaddress'];
var_dump($from);
}
And this is the result I get from that var_dump:
string(39) "Support Testing1"
How is that possible? And is there any way I can convert that to the correct string (I mean, with the right length?)
This is affecting my code, because now:
echo ('Support Testing1' == $from)
gives me false, when it should be true. Any ideas? Thanks!
Update: trim is not working either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我最好的猜测是
$header['fromaddress']
实际上是这样的,并且您在 var 转储中看不到电子邮件地址,因为浏览器将其视为 HTML 标记。
如果是这样,那么您需要删除
<...>
,可能还需要删除双引号。您可以尝试查看源 HTML 来确认。
My best guess is that
$header['fromaddress']
is really something likeAnd you don't see the email address in the var dump because the browser treats it like an HTML tag.
If this is so, then you need to remove the
<...>
, and probably the double quotes as well.You can try viewing the source HTML to confirm.
尝试:
两端可能都有隐藏的空白字符。
Try:
There may be hidden whitespace characters on either end.
错误的长度可能是编码问题!
尝试 :
A wrong length is probably a matter of encoding !
Try :