【问题标题】:How to compare a character with a hex value in php?如何在php中将字符与十六进制值进行比较?
【发布时间】:2013-08-16 09:34:16
【问题描述】:

我在 PHP 中有以下问题。我想将一个字符(字符串)与一个十六进制值进行比较,请参见以下示例代码:

// some key defined in some other application. I only can use KEY1
define("KEY1", 0x31);

// the test value
$sValue = '1';

// the comparison which I would like not to modify
print ($sValue == KEY1) ? "true" : "false";

0x31 代表 49 位小数,即字符“1”,我希望看到true。相反,我看到了false。如何在不使用KEY1 不同的情况下正确处理?可能sValue的类型不对?

【问题讨论】:

    标签: php comparison hex


    【解决方案1】:

    你在寻找

    print ($sValue == chr(KEY1)) ? "true" : "false";
    

    或者,或者,

    print (ord($sValue) == KEY1) ? "true" : "false";
    

    【讨论】:

      猜你喜欢
      • 2013-05-24
      • 2021-08-26
      • 2011-10-16
      • 1970-01-01
      • 1970-01-01
      • 2014-08-12
      • 1970-01-01
      • 2017-09-27
      • 2021-12-11
      相关资源
      最近更新 更多