Skip to content

Tyxiang/heading-array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

heading array

Parse HTML into an array based on Heading.

usage

include "heading-array.php";
$path = "demo.html";
$html = file_get_contents($path);
$array = heading_parse($html);
header('Content-type: application/json');
echo json_encode($array, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);

demo.html

<h1>heading-1</h1>
h1-content
<h2>heading-2</h2>
h2-content
<h2>heading-2</h2>
h2-content

output

{
  "others": "<h1>heading-1</h1>h1-content<h2>heading-2</h2>h2-content<h2>heading-2</h2>h2-content",
  "h1": [
    {
      "title": "heading-1",
      "content": "h1-content",
      "others": "<h2>heading-2</h2>h2-content<h2>heading-2</h2>h2-content",
      "h2": [
        {
          "title": "heading-2",
          "content": "h2-content",
          "others": ""
        },
        {
          "title": "heading-2",
          "content": "h2-content",
          "others": ""
        }
      ]
    }
  ]
}

About

Parse HTML into an array based on Heading.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages