こんにちは、
php的なことでよろしければ、
get_the_content();などを、$documentに置き換えてお考えください。
変数に入ったhtmlをphpの正規表現で、preタグの内側を抽出して、HTML エンティティに置換する意図です
htmlspecialcharsは、適宜置き換えてください。
<?php
$document =<<<DOC
ああああああああ
<pre>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="content-script-type" content="text/javascript" />
<meta http-equiv="content-style-type" content="text/css" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<link rev="made" href="mailto:" />
<link rel="stylesheet" href="" media="" />
<link rel="start" href="" />
<link rel="prev" href="" />
<link rel="next" href="" />
<link rel="help" href="" />
<title></title>
</head>
</pre>
えええええええええええ
<pre>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="content-script-type" content="text/javascript" />
<meta http-equiv="content-style-type" content="text/css" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<link rev="made" href="mailto:" />
<link rel="stylesheet" href="" media="" />
<link rel="start" href="" />
<link rel="prev" href="" />
<link rel="next" href="" />
<link rel="help" href="" />
<title></title>
</head>
</pre>
DOC;
$document = preg_replace_callback("|<pre>(.*?)</pre>|si",create_function('$matches','return "<pre>".htmlspecialchars($matches[1])."</pre>";'),$document);
echo $document;
トピック投稿者
LVP8
(@lvp8)
nobitaさん、回答ありがとうございます。
preg_replace_callback()は目にしたことはあったのですが、使い方が分からなかったのでとても参考になりました。この質問とは違うのですが、お陰で悩みが一つ減りました。