PHPでHTMLタグを削除するサンプルコード
PHPコード:
function noHTMLTag($content)
{
$content = preg_replace(“/<a[^>]*>/i",", $content);
$content = preg_replace(“/<\/a>/i", ", $content);
$content = preg_replace(“/<div[^>]*>/i",", $content);
$content = preg_replace(“/<\/div>/i",", $content);
$content = preg_replace(“/<font[^>]*>/i",", $content);
$content = preg_replace(“/<\/font>/i",", $content);
$content = preg_replace(“/<p[^>]*>/i",", $content);
$content = preg_replace(“/<\/p>/i",", $content);
$content = preg_replace(“/<span[^>]*>/i",", $content);
$content = preg_replace(“/<\/span>/i",", $content);
$content = preg_replace(“/<\?xml[^>]*>/i",", $content);
$content = preg_replace(“/<\/\?xml>/i",", $content);
$content = preg_replace(“/<o:p[^>]*>/i",", $content);
$content = preg_replace(“/<\/o:p>/i",", $content);
$content = preg_replace(“/<u[^>]*>/i",", $content);
$content = preg_replace(“/<\/u>/i",", $content);
$content = preg_replace(“/<b[^>]*>/i",", $content);
$content = preg_replace(“/<\/b>/i",", $content);
$content = preg_replace(“/<meta[^>]*>/i",", $content);
$content = preg_replace(“/<\/meta>/i",", $content);
$content = preg_replace(“/<!–[^>]*–>/i",", $content);
$content = preg_replace(“/<p[^>]*–>/i",", $content);
$content = preg_replace(“/style=.+?['|\"]/i",",$content);
$content = preg_replace(“/class=.+?['|\"]/i",",$content);
$content = preg_replace(“/id=.+?['|\"]/i",",$content);
$content = preg_replace(“/lang=.+?['|\"]/i",",$content);
$content = preg_replace(“/width=.+?['|\"]/i",",$content);
$content = preg_replace(“/height=.+?['|\"]/i",",$content);
$content = preg_replace(“/border=.+?['|\"]/i",",$content);
$content = preg_replace(“/face=.+?['|\"]/i",",$content);
$content = preg_replace(“/face=.+?['|\"]/",",$content);
$content = preg_replace(“/face=.+?['|\"]/",",$content);
$content=str_replace( “ ","",$content);
return $content;
}