简体   繁体   English

将非字母数字字符转换为 unicode 代码

[英]Convert non-alphanumeric characters to unicode codes

I receive a token in this format :我收到以下格式的令牌:

{"signature": "MEQCIFf4uQXQYR6fA48cHZMwR5K0bO/wsK5ygoCukmAfWslIAiAdc4kN1BEixxrreSI3W3x4a92+fFTw7/Ulqw9RuJPRzg\u003d\u003d","protocolVersion": "ECv1", "signedMessage": "{\"encryptedMessage\":\"HKdqg8pDCiAwaHmGeI+/7xIDXXCTSfK+/SERLh94NBX6l99w7vNgBenMCiaAGvO+nbHkmnaOnwMcq/DpRhFtCJuYjAGKA83UePYjleSgXp8AjTKUweXxpqNEVvexSeflHBQNcx4stvB7lhsCeW9SMhecebfkcgQyGlawBECXrsIWhfIRGHklC6KE18tlA0GfvsQLhKreWspHCxQjgiBDim6uR57aKzTzlTFGYK+IB1mMJbVFTrEeBnKOAlvdt8Nh4BH3DhrmV3HVl+Ydc9V2G6iGZ6EmPxe3QG5dC9aYGollEXieasTFZm1Bt/LQMdyHmQEd+cmdIQNfGhxzz5pWpLP9g8LuoG+8h69TYaVFY2o0FjP2vSuPqGhMlXhcWgb/gJsiAOLGkS2ZdFbhpQg3kEyS5f/h91Wuoxy08JHpFxsvzWL3skfJ5eQc/BykvHyzzxzK\",\"ephemeralPublicKey\":\"BFnxpfpfIeFLmJ/KM/GcQyhU0MBlEReejnKa71gKFnV+5N2t3WNBnaaNu02gjy7Z5d07XO5+O77Qx3abHnw5rwk\\u003d\",\"tag\":\"kbnLkGZKyDKBWQAh6AyCNL55V4SF8DiZ4PeIudtKBH0\\u003d\"}"}     

I need to json_decode it, do something with it then push it back.我需要json_decode进行json_decode ,用它做一些事情然后把它推回去。 If I json_decode it, I will get the \= character decoded to =, which is fine.如果我json_decode它,我会将\=字符解码为 =,这很好。 But how do I encode it back ?但是我如何将它编码回来? I think I played with every possible conversion function in PHP and I'm fresh out of ideas.我想我在 PHP 中使用了所有可能的转换函数,而且我的想法很新鲜。

Here's a sandbox to play around with : http://sandbox.onlinephpfunctions.com/code/b93defec84a9a6f22f5085fbb7628b5afa816d95这是一个可以玩的沙箱: http : //sandbox.onlinephpfunctions.com/code/b93defec84a9a6f22f5085fbb7628b5afa816d95

In normal work you do not need to encode = to \= but if you must use somthing like this:在正常工作中,您不需要将=编码为\=但如果您必须使用这样的东西:

$encoded = str_replace('=','\\\=', $encoded);

Note about your sandbox example: In your example the token variable signedMessage is json in json but after changes return as single json and not json in json like before changes.请注意您的沙箱示例:在您的示例中,令牌变量signedMessage是 json 中的 json 但更改后返回为单个 json 而不是 json 中的 json 就像更改之前一样。 maybe its fine for your application but check it也许它适合您的应用程序,但请检查它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM