bystro/html-table-converter 问题修复 & 功能扩展

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

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

bystro/html-table-converter

Composer 安装命令:

composer require bystro/html-table-converter

包简介

Converts HTML table to other format

README 文档

README

Author: Krzysztof Kubacki

Date: 04-03-2019

About

Converts HTML table to other format

This project is in ALPHA, meaning it is not fully functional!

Inspired by project https://github.com/tremblay/HTML-Table-to-JSON

Example

Given we have table bellow

First name Last name Points
Jill Smith 50
Eve Jackson 94

When we run the code bellow

<?php

$converter = HtmlTableConverter\HtmlTableConverterFactory::fromHtml($tableHtml);
var_dump($converter->convert()); 

Then will get the following result

array(3) {
  [0] =>
  array(3) {
    [0] =>
    string(10) "First name"
    [1] =>
    string(9) "Last name"
    [2] =>
    string(6) "Points"
  }
  [1] =>
  array(3) {
    'First name' =>
    string(4) "Jill"
    'Last name' =>
    string(5) "Smith"
    'Points' =>
    string(9) "<b>50</b>"
  }
  [2] =>
  array(3) {
    'First name' =>
    string(3) "Eve"
    'Last name' =>
    string(7) "Jackson"
    'Points' =>
    string(9) "<b>94</b>"
  }
}

Stripping HTML tags from column values

<?php

$converter = HtmlTableConverter\HtmlTableConverterFactory::fromHtml($tableHtml);
$converter->stripTagsFromColumnValues();
var_dump($converter->convert()); 
array(3) {
  [0] =>
  array(3) {
    [0] =>
    string(10) "First name"
    [1] =>
    string(9) "Last name"
    [2] =>
    string(6) "Points"
  }
  [1] =>
  array(3) {
    'First name' =>
    string(4) "Jill"
    'Last name' =>
    string(5) "Smith"
    'Points' =>
-    string(9) "<b>50</b>"
+    string(2) "50"
  }
  [2] =>
  array(3) {
    'First name' =>
    string(3) "Eve"
    'Last name' =>
    string(7) "Jackson"
    'Points' =>
-    string(9) "<b>94</b>"
+    string(2) "94"
  }
}

Removing header values

<?php

$converter = HtmlTableConverter\HtmlTableConverterFactory::fromHtml($tableHtml);
$converter->doNotIncludeHeaderRowInResult();
var_dump($converter->convert()); 
array(2) {
-  [0] =>
-  array(3) {
-    [0] =>
-    string(10) "First name"
-    [1] =>
-    string(9) "Last name"
-    [2] =>
-    string(6) "Points"
-  }
  [0] =>
  array(3) {
    'First name' =>
    string(4) "Jill"
    'Last name' =>
    string(5) "Smith"
    'Points' =>
    string(9) "<b>50</b>"
  }
  [1] =>
  array(3) {
    'First name' =>
    string(3) "Eve"
    'Last name' =>
    string(7) "Jackson"
    'Points' =>
    string(9) "<b>94</b>"
  }
}

Converting to JSON

<?php

$converter = HtmlTableConverter\HtmlTableConverterFactory::fromHtml($tableHtml);
$converter->convert(\HtmlTableConverter\Converter\Type::JSON);

Output format supported:

  • array
  • json

Install

Composer

In command line

composer require bystro/html-table-converter

or composer.json

"require": {       
    "bystro/html-table-converter": "^1.0"
}

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2019-03-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固