can';不要让php preg_(repace)在xhtml代码上处理更多行

can';不要让php preg_(repace)在xhtml代码上处理更多行,php,html,xhtml,preg-replace,Php,Html,Xhtml,Preg Replace,我正在尝试编写一个脚本,将一些html标记替换为其他或更多html标记。 选择preg_replace是因为它具有很好的变量效果。 例如: $xhtmlcode = preg_replace('@<h(.*?)>(.*?)</h(.*?)>@is','<h$1><sub>$2</sub></h$3>', $xhtmlinput); $xhtmlcode=preg_replace('@(.*)@is','$2',$xhtml

我正在尝试编写一个脚本,将一些html标记替换为其他或更多html标记。 选择preg_replace是因为它具有很好的变量效果。 例如:

$xhtmlcode = preg_replace('@<h(.*?)>(.*?)</h(.*?)>@is','<h$1><sub>$2</sub></h$3>', $xhtmlinput);
$xhtmlcode=preg_replace('@(.*)@is','$2',$xhtmlinput);
上面的代码工作正常,并给出了预期的结果,但之后我执行了以下操作:

$xhtmlcode = preg_replace('@<li(.*?)>(.*?)</li>@is','<li><sub>$2</sub></li>', $xhtminput);
$xhtmlcode=preg_replace('@(.*?@is','
  • $2
  • ',$XHTMLINPUT);
    只需支付NULL作为输出

    当使用其他类似的代码时,也会发生同样的情况, 现在我真的想知道为什么会发生这种情况:

      $xhthmlintput = '
      <span style="font-style:italic;font-weight:bold;font-size:12.5px">this is the test world</span>
      <span style="font-size:5.5px">this is the test planet</span>
      <span style="font-size:5.5px">test it well</span>';
    
    $xhthlintput='
    这是测试世界
    这是测试行星
    试一试",;
    
    我又遇到了同样的问题:

    $xhtmlcode = preg_replace( '@<span style="(.*?)bold(.*?)>(.*?)</span>@i', '<b>$3</b>', $xhtmlintput );
    

    $xhtmlcode=preg\u replace(“@向我们展示一些示例内容,你想替换什么,用什么…你获得空值,因为没有第二个捕获组。你需要使用
    $1
    而不是
    $2
    。但是你最好使用DOMDocument。你在正确的地方Casimir,我在那里发布了错误的代码,只是编辑了正确的代码。!使用
    DOMDocument
    DOMXpath
    相反,为什么不使用CSS来更改H1、H2、LI等的外观?