需要匹配的 2 个字符串并保持 HTML 输出字符串.例如,


need matched 2 string and remain html output string

>需要匹配的 2 个字符串并在匹配的字符串后添加

标签;

$string1="<p>he adventures <p>
<p>of < span >adolescence< /span > had taught Piet < span >Barol< /span > that he</p>";

$matching_with_string="he adventures
of adolescence had
taught Piet Barol 
that he";

我需要字符串 1 输出将与所有包含的 HTML 标签保持一致。

你可以尝试这样的事情

<?php
$strWithHTML="<p>he adventures <p>
<p>of < span >adolescence< /span > had taught Piet < span >Barol< /span > that he</p>";
$strWITHOUTHTML=str_replace(array('< ','/',' >','span'),'',strip_tags($string1));

编辑:

我想结果将我HTML格式

<?php
$strWithHTML="<p>he adventures <p>
<p>of < span >adolescence< /span > had taught Piet < span >Barol< /span > that he</p>";
echo htmlentities($strWithHTML);