▽1
●
LLマン ●50ポイント ベストアンサー |
<?php // JavaScript / styleタグ除去 $html = '<style type="text/css">test1</style>test2<script type="text/javascript">test3</script>test4'; $html = preg_replace('!<script.*?>.*?</script.*?>!is', '', $html); $html = preg_replace('!<style.*?>.*?</style.*?>!is', '', $html); echo $html; ?>
上記がJavaScript(とCSS)のタグを除去するPHPコードのサンプルになります。
オンラインコードサービスですが、一応動作を確認しました。
<?php $html = file_get_contents("http://www.yahoo.co.jp/"); $html = preg_replace('!<script.*?>.*?</script.*?>!is', '', $html); $html = preg_replace('!<style.*?>.*?</style.*?>!is', '', $html); echo strip_tags($html);
javascriptやCSSに対応してない(除去している)ので、
当然ながら、javascriptやCSSに対応したブラウザと表示は変わってしまいますが。