将 HTML 代码转换为人类可理解的代码

Converting HTML Code to human understandable code

我在数据库中的大部分内容都是这样记录的。这如何翻译成HTML代码结构?

<div class="main_title mb-4">n				<h2>New Arrival</h2>n				<span>Products</span>n				<p>Cum doctus civibus efficiantur in imperdiet deterruisset.</p>n			</div>n			<div class="isotope_filter">n				<ul><li><a href="http://www.example.com/index-2.html#0" id="all" data-filter="*">All</a></li><li><a href="http://www.example.com/index.html#0" id="popular" data-filter=".popular">Popular</a></li><li><a href="http://www.example.com/index-2.html#0" id="sale" data-filter=".sale">Sale</a></li></ul>n			</div>

转换为:

<div class="main_title mb-4">n <h2>New Arrival</h2>n <span>Products</span>n <p>Cum doctus civibus efficiantur in imperdiet deterruisset.</p>n </div>n <div class="isotope_filter">n <ul><li><a href="http://www.example.com/index-2.html#0" id="all" data-filter="*">All</a></li><li><a href="http://www.example.com/index.html#0" id="popular" data-filter=".popular">Popular</a></li><li><a href="http://www.example.com/index-2.html#0" id="sale" data-filter=".sale">Sale</a></li></ul>n </div>

您可以使用 html_entity_decode():

$str = '&#x3C;div class=&#x22;main_title mb-4&#x22;&#x3E;n&#x9;&#x9;&#x9;&#x9;&#x3C;h2&#x3E;New Arrival&#x3C;/h2&#x3E;n&#x9;&#x9;&#x9;&#x9;&#x3C;span&#x3E;Products&#x3C;/span&#x3E;n&#x9;&#x9;&#x9;&#x9;&#x3C;p&#x3E;Cum doctus civibus efficiantur in imperdiet deterruisset.&#x3C;/p&#x3E;n&#x9;&#x9;&#x9;&#x3C;/div&#x3E;n&#x9;&#x9;&#x9;&#x3C;div class=&#x22;isotope_filter&#x22;&#x3E;n&#x9;&#x9;&#x9;&#x9;&#x3C;ul&#x3E;&#x3C;li&#x3E;&#x3C;a href=&#x22;http://www.example.com/index-2.html#0&#x22; id=&#x22;all&#x22; data-filter=&#x22;*&#x22;&#x3E;All&#x3C;/a&#x3E;&#x3C;/li&#x3E;&#x3C;li&#x3E;&#x3C;a href=&#x22;http://www.example.com/index.html#0&#x22; id=&#x22;popular&#x22; data-filter=&#x22;.popular&#x22;&#x3E;Popular&#x3C;/a&#x3E;&#x3C;/li&#x3E;&#x3C;li&#x3E;&#x3C;a href=&#x22;http://www.example.com/index-2.html#0&#x22; id=&#x22;sale&#x22; data-filter=&#x22;.sale&#x22;&#x3E;Sale&#x3C;/a&#x3E;&#x3C;/li&#x3E;&#x3C;/ul&#x3E;n&#x9;&#x9;&#x9;&#x3C;/div&#x3E;';

echo html_entity_decode($str);

输出:

<div class="main_title mb-4">n              <h2>New Arrival</h2>n               <span>Products</span>n              <p>Cum doctus civibus efficiantur in imperdiet deterruisset.</p>n           </div>n         <div class="isotope_filter">n               <ul><li><a href="http://www.example.com/index-2.html#0" id="all" data-filter="*">All</a></li><li><a href="http://www.example.com/index.html#0" id="popular" data-filter=".popular">Popular</a></li><li><a href="http://www.example.com/index-2.html#0" id="sale" data-filter=".sale">Sale</a></li></ul>n            </div>