包()在PHP中。非法的十六进制数字警告 [英] pack() in php. Illegal hex digit warning

查看:1363
本文介绍了包()在PHP中。非法的十六进制数字警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在php中使用pack()时遇到一些问题

  $ currencypair =EUR / USD; 
$ buy_sell =buy;
$ alert_device_token = array(a,a,b);
$ message =您的。 $ currencypair。 。 $ buy_sell。 警戒价已经达到!;
$ payload ['aps'] = array(
'alert'=> $ message,
'badge'=> 1,
'sound'=>'默认'
);
$ payload = json_encode($ payload);

foreach($ alert_device_token as $ alert_device)
{
$ apnsMessage = chr(0)。 chr(0)。 chr(32)。
包('H *',str_replace('','',$ alert_device))。
chr(0)。 chr(strlen($ payload))。 $有效载荷;
echo $ apnsMessage;
}

现在有时我会看到下面的警告运行相同的代码 -

$ b:
$ b

 警告:pack()[function.pack]:类型H:非法的十六进制数字g in / code / FR2BVl 

非法的十六进制数字不断变化。



现场检查 here

pack 将十六进制数字为二进制,例如:

  echo pack(H *,2133)

产生!3 ,因为代码为0x21, 3 代码为0x33。由于 g 不是十六进制数字,因此会给出警告。要对包的 H 格式有用,参数必须是十六进制数。如果 $ alert_device 不是 - 你应该使用别的东西,这取决于它是什么以及你期望的结果。

i am having some problems using pack() in php

$currencypair = "EUR/USD";
$buy_sell = "buy";
$alert_device_token =array("a","a","b");
$message = "Your " . $currencypair . " " . $buy_sell . " alert price has been reached!";
$payload['aps'] = array (
  'alert' => $message,
  'badge' => 1,
  'sound' => 'default'
);
$payload = json_encode($payload);

foreach ($alert_device_token as $alert_device)
{
  $apnsMessage = chr(0) . chr(0) . chr(32) . 
                 pack('H*', str_replace(' ', '', $alert_device)) . 
                 chr(0) . chr(strlen($payload)) . $payload;
  echo $apnsMessage;
}

Now sometimes i get following warnings running the same code -

Warning: pack() [function.pack]: Type H: illegal hex digit g in /code/FR2BVl

the illegal hex digit keeps varying though. Any ideas about this warning and ways to remove it.

check it live here

解决方案

pack converts hexadecimal number to binary, e.g.:

  echo pack("H*", "2133")

produces !3, since ! has code 0x21 and 3 has code 0x33. Since g is not hex digit, warning is given. To be useful for pack's H format, the argument must be hex number. If $alert_device isn't - you should use something else, depending on what it is and what you expect as the result.

这篇关于包()在PHP中。非法的十六进制数字警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆