Skip to content

Instantly share code, notes, and snippets.

@cockok
Created April 21, 2021 09:35
Show Gist options
  • Save cockok/335f066393cfcd889e51c01fafb4e9b3 to your computer and use it in GitHub Desktop.
Save cockok/335f066393cfcd889e51c01fafb4e9b3 to your computer and use it in GitHub Desktop.
HTMLのタグを補完し正規化する
<?php
$html = '<p>hoge';
$dom = new DOMDocument();
$dom->loadHTML('<?xml encoding="utf-8" ?>' . $html);
$html = str_replace(['<html><body>', '</body></html>'], '', $dom->saveHTML($dom->documentElement));
echo $html;
// <p>hoge</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment