2012-03-21 1 views
0

PHP Tidyをインクルードされたスクリプトとして使用していますが、ほとんどの場合(不完全な場合)、タグから名前属性を削除するようには見えません。私はTidyを実行する前にPHPのシンプルなHTML DOMを使用してそれらを削除することを含め、すべてを削除しようとしましたが、やり続けます。PHP/HTML Tidy:anchor-as-name = noは機能していないようですか?

私はこの問題を広範囲に調査しましたが、名前としてアンカーを使用することを推奨している人々からのものですから、それは機能しなければならず、私がやっていることが機能していないということについては何かがあります。

私のTidyの設定は次のようになっていますが、他の何かがanchor-as-name要素を上書きしているのでしょうか?私はそれを助けてくれるかもしれない場合に備えて、それを底に移動しましたが、そうではなかったようです。私もそれをfalseに設定しようとしましたが、それは助けにもなりませんでした。

ショーボディのみ考えてみれば
$tidy_config = Array(

    'break-before-br'  => 'no', 
    'clean'     => 'clean', 
    'doctype'    => 'strict', 
    'drop-empty-paras'  => 'yes', 
    'drop-font-tags'  => 'yes', 
    'force-output'   => 'yes', 
    'indent'    => 'yes', 
    'indent-attributes'  => 'no', 
    'indent-spaces'   => 2, 
    'input-encoding'  => 'utf8', 
    'join-styles'   => 'no', 
    'literal-attributes' => 'yes', 
    'logical-emphasis'  => 'yes', 
    'lower-literals'  => 'yes', 
    'merge-divs'   => 'no', 
    'merge-spans'   => 'yes', 
    'output-encoding'  => 'ascii', 
    'output-xhtml'   => 'yes', 
    'output-bom'   => 'no', 
    'preserve-entities'  => 'yes', 
    'quiet'     => 'yes', 
    'quote-ampersand'  => 'yes', 
    'quote-marks'   => 'no', 
    'quote-nbsp'   => 'yes', 
    'show-body-only'  => 'yes', 
    'show-errors'   => 0, 
    'show-warnings'   => 0, 
    'sort-attributes'  => 'alpha', 
    'tidy-mark'    => 'no', 
    'vertical-space'  => 'yes', 
    'wrap'     => '0', 
    'wrap-attributes'  => 'no', 
    'anchor-as-name'  => 'no' 
); 

は、いずれか、仕事ができること...多分全部は単に無視されていると私は根本的に間違って何かをやっているようではありませんか?

何か手がかりと助力を大いに感謝します。

Oezi:質問の更新に関するヒントをありがとう。これは私がここで尋ねた最初の質問です。

私はidタグを使用しています。これは、一般的に(関連するすべての変数はあらかじめ定義されている)何が起こるかです:

require_once $docRoot . '/htmldom/simple_html_dom.php'; 
require $this_dir . '/includes/create-tidy-object.php'; 
$string1 = "<a id='anchor1'>First Anchor Text</a>"; 
$string2 = "<a id='anchor2' name='anchor2'>Second Anchor Text</a>"; 
$string3 = "<a id='anchor3'>Third Anchor Text</a>"; 
$tidy->parseString($string1,$tidy_config,'utf8'); 
$tidy->cleanRepair(); 
$revised_string_1 = $tidy; 
print "<pre>Revised String 1:\n" . htmlentities($revised_string_1) . "\n\n"; 
$tidy->parseString($string2,$tidy_config,'utf8'); 
$tidy->cleanRepair(); 
$revised_string_2 = $tidy; 
print "Revised String 2:\n" . htmlentities($revised_string_2) . "\n</pre>\n"; 
$stringdom3 = str_get_html($string3); 
foreach($stringdom3->find('a[id]') as $anchor) { $anchor->name = null; } 
$revised_string_3 = $stringdom3; 
print "<pre>\nRevised String 3, after PHP Simple HTML DOM Parser:\n"; 
print htmlentities($revised_string_3) . "\n</pre>\n"; 
$tidy->parseString($revised_string_3,$tidy_config,'utf8'); 
$tidy->cleanRepair(); 
$revised_string_3a = $tidy; 
print "<pre>Revised String 3, after going through both:\n"; 
print htmlentities($revised_string_3a) . "\n\n"; 

は(読みやすさのために追加改行で)生成されます

Revised String 1: 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> 
<html> 
<head> 
<title></title> 
</head> 
<body> 
<a id='anchor1' name="anchor1">First Anchor Text</a> 
</body> 
</html> 

Revised String 2: 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> 
<html> 
<head> 
<title></title> 
</head> 
<body> 
<a id='anchor2' name='anchor2'>Second Anchor Text</a> 
</body> 
</html> 

Revised String 3, after PHP Simple HTML DOM Parser: 
<a id='anchor3'>Third Anchor Text</a> 

Revised String 3, after going through both: 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> 
<html> 
<head> 
<title></title> 
</head> 
<body> 
<a id='anchor3' name="anchor3">Third Anchor Text</a> 
</body> 
</html> 

だから、きちんとしたアンカーにもかかわらず、名前タグを追加しているだけでなく、 -as-nameがnoに設定されている場合、show-body-onlyがyesに設定されているにもかかわらず、ボディの外にタグを生成しています。

明白な解決策はちょうど単純なhtmlのdomから私が私の望むものを得るので、ちょっと使いきれないように思えるかもしれませんが、私は百万文字以上のファイル(500-1000ページの文書) Wordの哀れなバージョンのHTMLで書かれている - それは本当に多くの他の機能に役立ちます。

答えて

0

the documentationから:

"なし" に設定した場合は、id属性がの存在または追加されている場合は、[...]、既存のname属性は、削除されます。

あなたはそれについての情報を与えていないので、「動作しない」アンカーにIDを設定していないと仮定します。

+0

とにかくコメントに追加情報を投稿しないでください。質問を編集し、代わりに例を追加してください。 – oezi

関連する問題