0
我試圖製作一個Wordpress插件,因此我試圖操縱我的DOM(帖子內容)。目前,我有這樣的代碼:在PHP中解析HTML時作爲輸入提供的空字符串
<?php
function mb_find_my_image($content) {
if(is_home()) { /* if is home start */
$dom = new domDocument;
$dom->loadHTML($content);
$dom->preserveWhiteSpace = false;
} /* if is home end */
return $content;
}
add_filter('the_content', 'mb_find_my_image');
?>
但我一直得到以下錯誤:
Empty string supplied as input
我已經使用了HTML元素的任何其他自定義字符串試圖和它的作品。此外,我一直在使用var_export嘗試($內容,真實),這一定程度上解決了這個問題,但我得到的錯誤,如:
Call to a member function getAttribute() on a non-object
什麼,我哪裏做錯了? 我正在使用WAMP服務器在本地計算機上運行此腳本。
的var_dump($內容)給我:
null
string post content (actual html that is the post) ... (length=805)
看來你沒有正確傳遞參數。檢查你在哪裏調用你的函數,看看傳入的內容。 – Kyle
@KyleGibbens你能告訴我該怎麼做嗎?我還是PHP和Wordpress的新手。 – Mentalhead
你的'mb_find_my_image'函數位於哪個文件中? – montrealist