简体   繁体   English

使用 php 解析 zxing qrcode 解码响应

[英]Parsing zxing qrcode decode response with php

I'm using console java tool Zxing to decode qr codes from images.我正在使用控制台 java 工具Zxing从图像中解码二维码。 I call it from php and it works fine but now I'm stuck with parsing the response that it gives:我从 php 调用它,它工作正常,但现在我坚持解析它给出的响应:

file:/home/users/public_html/playground/qrcode/images/new.png (format: QR_CODE, type: TEXT):
Raw result:
{"uniqueid":44819,date:131232211}
Parsed result:
{"uniqueid":44819,date:131232211}
Found 4 result points.
  Point 0: (22.5,88.5)
  Point 1: (22.5,22.5)
  Point 2: (88.5,22.5)
  Point 3: (79.5,79.5)

What I need is to get {"uniqueid":44819,date:131232211} portion.我需要的是获得 {"uniqueid":44819,date:131232211} 部分。 I tried something like:我试过类似的东西:

$response=explode(" ",$response);
$response=preg_replace(array("/Parsed/","/result:/"),array("",""),explode(" ",$response[5]));
$response=$a[0];

And also tried substring with strpos .并且还尝试substringstrpos But it is only suitable for non-spaced strings.但它只适用于非间隔字符串。 So I want an universal solution for that.所以我想要一个通用的解决方案。

Also I dont really know if there is any way to make zxing return response in another more reliable format so I can simply avoid these php manipulations.另外我真的不知道是否有任何方法可以使 zxing 以另一种更可靠的格式返回响应,所以我可以简单地避免这些 php 操作。

Some cool regular expression to cut this out?一些很酷的正则表达式来消除这个? Maybe.也许。 But I'm not such good at it.但我不是很擅长。

Ideas?想法?

You're trying to parse the output of the command-line program, which is not meant as an API.您正在尝试解析命令行程序的 output,这并不意味着 API。 The output is pretty predictably in the format you say, though -- why is it hard to parse? output 在你说的格式中是可以预见的,不过——为什么它很难解析? It's open source, so you could modify the program to print whatever you like.它是开源的,因此您可以修改程序以打印您喜欢的任何内容。 Why bother parsing output you don't like, just modify the output?为什么还要解析你不喜欢的output,只修改output?

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

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