21,886
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="gb2312" ?>
<rss version="2.0">
<item>
<title>标题1</title>
<description>
<table>
<tbody>
<tr align="center">
<td><p>内容......</p></td>
</tr>
</tbody>
</table>
</description>
</item>
<item>
<title>标题2</title>
<description>
<table>
<tbody>
<tr align="center">
<td><p>内容......</p></td>
</tr>
</tbody>
</table>
</description>
</item>
</rss>
<?xml version="1.0" encoding="gb2312" ?>
<rss version="2.0">
<item>
<title>标题1</title>
<description>
<table>
<tbody>
<tr align="center">
<td><p>内容......</p></td>
</tr>
</tbody>
</table>
</description>
</item>
<item>
<title>标题2</title>
<description>
<table>
<tbody>
<tr align="center">
<td><p>内容......</p></td>
</tr>
</tbody>
</table>
</description>
</item>
</rss>
$s = <<< TEXT
<?xml version="1.0" encoding="gb2312" ?>
<rss version="2.0">
<item>
<title>标题1</title>
<description>
<table>
<tbody>
<tr align="center">
<td><p>内容......</p></td>
</tr>
</tbody>
</table>
</description>
</item>
<item>
<title>标题2</title>
<description>
<table>
<tbody>
<tr align="center">
<td><p>内容......</p></td>
</tr>
</tbody>
</table>
</description>
</item>
</rss>
TEXT;
$p = '/<(description)>(.*?)<\/\\1>/ise';
$r = '"<$1>".htmlspecialchars("$2", ENT_NOQUOTES)."</$1>"';
echo preg_replace($p, $r, $s);
<?xml version="1.0" encoding="gb2312" ?>
<rss version="2.0">
<item>
<title>标题1</title>
<description>
<table>
<tbody>
<tr align="center">
<td><p>内容......</p></td>
</tr>
</tbody>
</table>
</description>
</item>
<item>
<title>标题2</title>
<description>
<table>
<tbody>
<tr align="center">
<td><p>内容......</p></td>
</tr>
</tbody>
</table>
</description>
</item>
</rss>