要傳遞多個 CSS 規則,以及類別、ID 或任何 HTML 屬性到高亮顯示的元素,我們可以利用跳脫引號來關閉內嵌樣式
ini_set('highlight.string', '#F8F8F8 ; font-size:1.4em\" class=\'string\' ');這些函式的行為會受到 php.ini 中設定的影響。
| 名稱 | 預設值 | 可變更性 | 更新日誌 |
|---|---|---|---|
| ignore_user_abort | "0" | INI_ALL |
|
| highlight.string | "#DD0000" | INI_ALL |
|
| highlight.comment | "#FF8000" | INI_ALL |
|
| highlight.keyword | "#007700" | INI_ALL |
|
| highlight.default | "#0000BB" | INI_ALL |
|
| highlight.html | "#000000" | INI_ALL |
|
| browscap | NULL | INI_SYSTEM |
以下是設定指令的簡短說明。
ignore_user_abort 布林值
預設為 false。如果改為 true,即使客戶端中止連線,腳本也不會終止。
另請參閱 ignore_user_abort()。
highlight.bg 字串highlight.comment 字串highlight.default 字串highlight.html 字串highlight.keyword 字串highlight.string 字串語法高亮模式的顏色設定。任何在 <font color="??????"> 中可接受的值都可以使用。
browscap 字串瀏覽器能力檔案的名稱(例如:browscap.ini)和位置。另請參閱 get_browser()。
要傳遞多個 CSS 規則,以及類別、ID 或任何 HTML 屬性到高亮顯示的元素,我們可以利用跳脫引號來關閉內嵌樣式
ini_set('highlight.string', '#F8F8F8 ; font-size:1.4em\" class=\'string\' ');*** 補充前一條訊息 ***
要直接從 CSS 檔案更改樣式,建議僅使用類別,而不是將樣式寫死在程式碼中。
<?php
// 建立一個包含預設 PHP 函數的陣列
$functions = array("default", "html", "keyword", "string", "comment");
// 將顏色代碼(例如:#FF8000)替換為類別名稱(例如:"highlight-comment")
foreach ($functions as $value) {
ini_set("highlight.$value", "highlight-$value;");
}
$content = highlight_file($filename, true);
// 或
$content = highlight_string($string, true);
// 在 $content 中將 style="color: highlight-function" 轉換為 class="highlight-function"
// 這允許您僅修改預設函數
foreach ($functions as $value) {
$content = preg_replace("/style=\"color: highlight-$value;\"/", "class=\"highlight-$value\"", $content);
}
?>
然後在 CSS 檔案中(例如):
.highlight-html { color: #000000; }
.highlight-default { color: #0000bb; }
.highlight-keyword { color: #007700; font-weight: bold; }
.highlight-string { color: #dd0000; }
.highlight-comment { color: #ff8000; }要直接從 CSS 檔案更改樣式,建議僅使用類別,而不是將樣式寫死在程式碼中。
<?php
$functions = array("default", "html", "keyword", "string", "comment");
foreach ($functions as $value) {
ini_set("highlight.$value", "highlight-$value;");
}
?>
然後在 CSS 檔案中(例如):
.highlight-html { color: #000000; }
.highlight-default { color: #0000bb; }
.highlight-keyword { color: #007700; font-weight: bold; }
.highlight-string { color: #dd0000; }
.highlight-comment { color: #ff8000; }