PHP:无效的字符串不允许我正确比较它

发布于 2024-12-14 10:22:14 字数 691 浏览 0 评论 0原文

由于某种原因,在数组内生成了一个非常奇怪的字符串,我不知道如何处理它...我正在获取该字符串并使用以下代码输出它:

    $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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

做个ˇ局外人 2024-12-21 10:22:14

我最好的猜测是 $header['fromaddress'] 实际上是这样的,

"Support Testing1" <[email protected]>

并且您在 var 转储中看不到电子邮件地址,因为浏览器将其视为 HTML 标记。

如果是这样,那么您需要删除 <...>,可能还需要删除双引号。

您可以尝试查看源 HTML 来确认。

My best guess is that $header['fromaddress'] is really something like

"Support Testing1" <[email protected]>

And 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.

感性不性感 2024-12-21 10:22:14

尝试:

$from = trim($header['fromaddress']));

两端可能都有隐藏的空白字符。

Try:

$from = trim($header['fromaddress']));

There may be hidden whitespace characters on either end.

楠木可依 2024-12-21 10:22:14

错误的长度可能是编码问题!

尝试 :

var_dump( utf8_decode( $header['fromaddress'] ) );

A wrong length is probably a matter of encoding !

Try :

var_dump( utf8_decode( $header['fromaddress'] ) );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文