1

我想保存(转储)修改后的 HTML。

php_simplehtmldom通过保存功能使用了库和转储。

但是simplehtmldom库会自动修改错误的语法。

任何人都知道“如何在不替换错误语法的情况下忽略保存?”

我不想像后续那样替换。我只想为输入标签添加标题属性。

前任)

    $oSimpleHtmlParser = file_get_html(
                            $sPath,
                            $use_include_path=false,
                            $context=null,
                            $offset=-1,
                            $maxLen=-1,
                            $lowercase=false,
                            $forceTagsClosed=false,
                            $target_charset=DEFAULT_TARGET_CHARSET,
                            $stripRN=false,
                            $defaultBRText=DEFAULT_BR_TEXT,
                            $defaultSpanText=DEFAULT_SPAN_TEXT
                         );
    $oRetVal = $oSimpleHtmlParser->find('input');
    foreach($oRetVal as $key => $val){
        if($val->title == "") {
            $oRetVal[$key]->title = "title";
        }
    }
    $oSimpleHtmlParser->save($sPath);

保存结果

<table border=0 cellpadding=0 cellspacing=0 width=295 style="padding-left:5">
      <tr><td height="12" colspan="2"></td></tr>
      <tr><td height="20" class="fc_55"><img src="/web/design/{$_DESIGN}/images/dot_2px.gif" style="margin:0 0 3 0"></td>
-         <td align="right" class="fc_55"" width="78">[2007-02-21]</td>
+         <td align="right" class="fc_55">[2007-02-21]</td>
-         <input type="text" style="width:251" align="absmiddle" class="border">
+         <input type="text" style="width:251" align="absmiddle" class="border" title="title">

      </tr>

预期结果

<table border=0 cellpadding=0 cellspacing=0 width=295 style="padding-left:5">
      <tr><td height="12" colspan="2"></td></tr>
      <tr><td height="20" class="fc_55"><img src="/web/design/{$_DESIGN}/images/dot_2px.gif" style="margin:0 0 3 0"></td>
          <td align="right" class="fc_55"" width="78">[2007-02-21]</td>
-         <input type="text" style="width:251" align="absmiddle" class="border">
+         <input type="text" style="width:251" align="absmiddle" class="border" title="title">
      </tr>
4

0 回答 0