編輯:這不是關於未定義變量的一般問題,而是關於這個特定的代碼示例,它沒有指定從哪裏拉動變量。
我正在嘗試使用s9e \ TextFormatter設置標記的HTML白名單,如文檔here。
這裏是我的代碼:
use s9e\TextFormatter\Configurator;
function htmlFormat()
{
$configurator = new Configurator;
$configurator->plugins->load('HTMLElements');
$configurator->HTMLElements->allowElement('b');
$configurator->HTMLElements->allowAttribute('b', 'class');
$configurator->HTMLElements->allowElement('i');
// Get an instance of the parser and the renderer
extract($configurator->finalize());
$text = '<b>Bold</b> and <i>italic</i> are allowed, but only <b class="important">bold</b> can use the "class" attribute, not <i class="important">italic</i>.';
$xml = $parser->parse($text);
$html = $renderer->render($xml);
}
htmlFormat();
然而變量$parser
和$renderer
在該示例代碼從未定義。我不知道如何將它們整合到這個代碼中,是嗎?
'$ parser'&'$ renderer'可以是任何東西。也許回顧一下你從這個複製過來的代碼來理解這些變量究竟是什麼。 – Augwa
[PHP的:「注意:未定義的變量」,「注意:未定義的索引」和「注意:未定義的偏移量」)可能的重複(http://stackoverflow.com/questions/4261133/php-notice-undefined-variable- notice-undefined-index-and-notice-undef) – Qirel
這不是關於未定義變量的一般問題,而是關於這個特定腳本的問題。 –