2024 PHP Conference Japan

範例

目錄

新增註解

使用者提供的註解 4 則註解

Brad
15 年前
清理 HTML 片段(目前物件導向支援似乎有點半調子)

這將確保所有標籤都已關閉,而不會在其周圍添加任何 html/head/body 標籤。

<?php
$tidy_config
= array(
'clean' => true,
'output-xhtml' => true,
'show-body-only' => true,
'wrap' => 0,

);

$tidy = tidy_parse_string($html_fragment, $tidy_config, 'UTF8');
$tidy->cleanRepair();
echo
$tidy;
?>
dan [@t] authenticdesign [d_o_t] net
16 年前
如果您只是要快速簡單地輸出您建立的 HTML 程式碼,請使用以下技巧...

<?php
$html
= 'a chunk of html you created';
$config = array(
'indent' => true,
'output-xml' => true,
'input-xml' => true,
'wrap' => '1000');

// Tidy
$tidy = new tidy();
$tidy->parseString($html, $config, 'utf8');
$tidy->cleanRepair();
echo
tidy_get_output($tidy);
?>

... 這個方法似乎每次都能得到我想要的結果。
Dmitri Snytkine cms.lampcms.com
14 年前
關於設定選項的重要注意事項
如果您閱讀此頁面上的快速參考
http://tidy.sourceforge.net/docs/quickref.html
您可能會認為設定選項的布林值可以設定為 'y' 或 'yes' 或 'n' 或 'no'
但這對於 PHP 中的 tidy 擴充套件來說是不正確的。

布林值必須僅設定為 true 或 false(不帶引號或其他內容),否則 tidy 只會忽略您的設定。它不會產生任何錯誤或警告,但只會忽略您的 'yes' 或 'no' 值。

例如,以下設定陣列將不會產生預期的效果
<?php $config = array('drop-proprietary-attributes' => 'yes'); ?>

您必須將選項設定為 true
<?php $config = array('drop-proprietary-attributes' => true); ?>
nicolas [at] adaka [dot] fr
16 年前
這似乎是整理 HTML 片段(以有效的 XHTML 語法)的正確設定。

<?php
$tidy_config
= array(
'clean' => true,
'drop-proprietary-attributes' => true,
'output-xhtml' => true,
'show-body-only' => true,
'word-2000' => true,
'wrap' => '0'
);
?>
To Top