开发者

Parsing zxing qrcode decode response with php

开发者 https://www.devze.com 2023-03-28 00:38 出处:网络
I\'m using console java tool Zxing to decode qr codes from images. I call it from php and it works fine but now I\'m stuck with parsing the response that it gives:

I'm using console java tool Zxing to decode qr codes from images. I call it from php and it works fine but now I'm stuck with parsing the response that it gives:

file:/home/users/public_html/playground/qrcode/images/new.png (format: QR_CODE, type: TEXT):
Raw result:
{"uniqueid":44819,date:131232211}
Parsed result:
{"uniqu开发者_如何学JAVAeid":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. 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. 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.

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. The output is pretty predictably in the format you say, though -- why is it hard to parse? 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?

0

精彩评论

暂无评论...
验证码 换一张
取 消