duan0802 2017-08-16 03:52
浏览 109

如何将UTF-8或UTF-16字符插入PHP字符串

We have an existing system which reads a barcode and saves it in a database. When the saved barcode data is looked in the database it appears as 102\u001d211065\u001d9120 and when a var_dump is done it looks like "101\x1D21881\x1D9120.

I see that a group separator character is inserted into the string, which is \u001d and \x1D (https://codepoints.net/U+001D?lang=en)

I have the data of the barcode in a separate table in multiple columns. What I need to do is to write a query that finds a matching barcode. For this, I want to join the data columns, including the group separator character between them.

My question is, how do I create a string in PHP with the group separator character included between the concatenating strings?

  • 写回答

1条回答 默认 最新

  • drxm72811 2017-08-19 03:32
    关注

    The problem was single quotes vs double quotes. When double quotes are used the UTF8, UTF16, etc. does get converted. So to include UTF characters the following needs to be used.

    echo "This will \x1d work";
    

    Initially I was trying to echo the string using single quotes which does not convert.

    echo "This does not \x1d work";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体