如何在 PHP 中在 HTML 中顯示 XML?


如果字串已預格式化,並且需要相同的純文字表示形式,那麼它可以包含在 HTML <pre/> 標記中,並且可以使用 HTML 實體來轉義尖括號。這已在下面顯示 −

<?PHP echo '<pre>', htmlentities($string), '</pre>'; ?>

將字串分配給字串型別,並在上面顯示 XML 在 HTML 中顯示 −

示例

 即時演示

<?php
$string = "
<example>
   <example>
      <example_value>EXAMPLE</example_value>
   </example>
</example> ";
echo '<pre>', htmlentities($string), '</pre>';
?>

輸出

這將產生以下輸出 −

<example>
   <example>
      <example_value>EXAMPLE</example_value>
   </example>
</example>

更新於:09-Apr-2020

2K+ 瀏覽

啟動你的 職業生涯

透過完成課程獲得認證

開始
廣告