TOP ▲
itcore TOP プログラムパーツ
uTagDel タグを削除する。 | itcore 2020年
PHP
関数
<?php
  function uTagDel($html) {
    return preg_replace('/<[^>]*>/', "", $html);
  }
?>
テストプログラム
<?php include_once "uTagDel.func"; ?>
<?php
  $html = "<a><b>成功</b></a>"; $ret = uTagDel($html); echo htmlspecialchars($ret)."<br>\n";
  $html = "<a><b>失敗</b></a>"; $ret = preg_replace('/<.*>/', "", $html); echo htmlspecialchars($ret)."<br>\n";  // これだと入れ子のタグを正しく削除できない。
?>
実行結果
成功