PHP Urlencoded字符串在SMS正文中无法正常显示

时间:2016-01-25 08:23:02

标签: php string encoding

我正在尝试发送一个编码字符串,将其附加到用于发送BULK SMS的api url。但并非所有的characeters都被正确编码。在使用[2016-01-25 12:45:30,195] ERROR [Replica Manager on Broker 2]: Error when processing fetch request for partition [WordCount,4] offset 335517 from consumer with correlation id 0. Possible cause: Attempt to read with a maximum offset (335515) less than the start offset (335517). (kafka.server.ReplicaManager) 之前,我已尝试在字符串上使用utf8_encodehtmlentitieshtmlspecialchars,但这也无效。由于它是外部api调用,因此它们只使用urldecode来显示我无法更改的字符串。因此,需要对以下字符串中存在的特殊字符进行编码以在生成的SMS中正确显示它。

示例字符串:

urlencode
  

2016带来了“兰花”的新年促销活动。 “家居装饰”。

应用urlencode和htmlentities后

$message = '2016 brings with it a new year sale at “Orchid” & “home n décor”.';

我得到以下输出 -

  

2016 +带来+与+它+ A +新+年+销售+在+%26ldquo%3BOrchid%26rdquo%3B +%26安培%3B +%26ldquo%3Bhome + N + d%26eacute%3Bcor%26rdquo%3B。< / p>

当我尝试在此使用urlencode(htmlentities($message, ENT_QUOTES, 'UTF-8')) 时,它会按预期显示结果 -

  

2016带来了“兰花”的新年促销活动。 “家居装饰”。

当我尝试将编码的输出字符串作为url参数发送并回显参数时,我得到了完全相同的结果,甚至没有使用urldecode

但问题出在我的短信身上,它总是以下列模式显示 -

urldecode

为什么不在SMS中显示已解码的字符串?怎么做到这一点?它显示正常的编码字符,如&amp;没有任何问题,因为它编码为2016 brings with it a new year sale at &ldquo;Orchid&rdquo; &amp; &ldquo;home n d&eacute;cor&rdquo;. 。但导致双引号或%26等字符出现问题。任何人都可以建议任何解决方法吗?

1 个答案:

答案 0 :(得分:0)

使用:

$message = "Message Text";

代替:

$message = urlencode("Message Text");