承接 battye/php-array-parser 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

battye/php-array-parser

最新稳定版本:v1.0.10

Composer 安装命令:

composer require battye/php-array-parser

包简介

Parse text representation of a PHP array into an actual PHP array.

README 文档

README

A small library to parse text representations of a PHP array and return an actual PHP array.

Installation

Run composer install to run this script (and tests) in a standalone way. Alternatively, this can be used as a dependency in another project by running composer require battye/php-array-parser "~1.0".

Reference the namespace at the top of your PHP files to utilise the included classes:

use battye\array_parser\parser;
use battye\array_parser\tokens;

If you notice any bugs, please raise an issue or pull request.

Example

In both of the following examples, $result would contain a PHP array containing the representation of the string or text file provided.

Raw String

To parse a simple array is very easy:

$value = "array(0 => array('one' => 1, 'two' => 'two'));";
$result = parser::parse_simple($value);

In this case, $result would produce the following:

array(1) {
  [0] =>
  array(2) {
    'one' =>
    int(1)
    'two' =>
    string(3) "two"
  }
}

Regex

Regular expressions can also be used to parse complex files and extract array values:

$regex = '/\$lang\s+=\s+array_merge\(\$lang, array\((.*?)\)\);/s';
$file = __DIR__ . '/files/test_lang.php';
$result = parser::parse_regex($regex, $file);

Tests

Latest Stable Version Total Downloads GitHub Actions CI

The unit tests provide good examples of how to utilise this library and can be found in the tests/ directory. To execute the unit tests, run:

vendor/bin/simple-phpunit tests/

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固