panduanvip/ronolo-json-extract 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

panduanvip/ronolo-json-extract

Composer 安装命令:

composer require panduanvip/ronolo-json-extract

包简介

Extracts JSON from strings and returns PHP arrays.

README 文档

README

Abstract

Small class, which will try to extract JSON strings from a string. There are two functions which will achieve that.

This fork fixes the problem on "Array and string offset access syntax with curly braces that no longer supported"

Installation

composer require panduanvip/ronolo-json-extract

Use

<?php
use RoNoLo\JsonExtractor\JsonExtractorService; 
 
$jsonExtractor = new JsonExtractorService();
 
// $html contains a HTML full page string (as example)
$html = file_get_content('foo/bar.html');
$json = $jsonExtractor->extractJsonAfterIdentifier("foobar", $html);

This will expect the identifier somewhere in the given string. The identifier position will act as starting point and the next valid JSON object or array will be returned as PHP array.

<?php
use RoNoLo\JsonExtractor\JsonExtractorService; 
 
$jsonExtractor = new JsonExtractorService();
 
// $html contains a HTML full page string
$html = file_get_content('foo/bar.html');
$vars = $jsonExtractor->extractAllJsonData($html);

This will look for any JSON objects or arrays in the string and returns them as an array of arrays of JSON data. You may have to check the list of JSON data for data you was looking for.

It is recommend to break HTML down into smaller parts with a DOM parser, like symfony/dom-crawler or similar. The smaller the portion is which shall be parsed the better will be the result.

For example, if you parse a HTML string and expect the JSON inside the

... tags, feed only the text inside the tags to the json-extract functions.

Can extract

Correct JSON

{
  "paging": {
    "pageNum": 1,
    "pageSize": 25,
    "numFound": 1,
    "last": 1,
    "lastUncapped": 1,
    "display": [1]
  }
}

Incorrect Single-Quotes JSON

{
  'paging': {
    'pageNum': 1,
    'pageSize': 25,
    'numFound': 1,
    'last': 1,
    'lastUncapped': 1,
    'display': [1]
  }
}

Javascript Objects (Thanks to the CJSON.php)

{
  paging: {
    pageNum: 1,
    pageSize: 25,
    numFound: 1,
    last: 1,
    lastUncapped: 1,
    display: [1]
  }
}

EOF

统计信息

  • 总下载量: 80
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 2
  • 开发语言: HTML

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-05-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固