0
好的,所以我一直試圖從不同的div類獲取特定內容放在表中。我正在自定義我的WordPress的網站。這裏是想要通過php獲取div內的內容
//loops through posts
while (have_posts()) : the_post();
$doc = new DomDocument;
$doc ->validateOnParse = true;
$link = " ' " . get_permalink() . " ' ";
//this is where the trouble lies. get error
/*Warning: file_get_contents(' http://www.uwarc.org/?p=60 ') [function.file-get-contents]: failed to open stream: No such file or directory in /home/uwarco5/public_html/wp-content/themes/thesis_185/custom/custom_post_loop.php on line 98
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Empty string supplied as input in /home/uwarco5/public_html/wp-content/themes/thesis_185/custom/custom_post_loop.php on line 98 */
$doc->loadHtml(file_get_contents($link));
echo "<tr onclick=" . $quote . "DoNav(". $quote1 . "get_post_class('site', null) " . $quote1. ");" . $quote . ">" ;
echo "<td align =" . $quote . "center" . $quote . " >" ;
echo "<div id =". $quote . "org_logo" . $quote . "> <img src =". $quote ;
var_dump($doc->getElementByClass('img')) ;
echo $quote . "width = ".$quote. '150' . $quote. "; </div> " ;
the_title();
echo "</td>";
echo "<td>" . var_dump($doc->getElementByClass('courses')) . "</td>";
echo "<td>";
var_dump($doc->getElementByClass('description'));
echo "</td>";
echo "</tr>
endwhile;?>
嘗試'$ doc-> loadHTMLFile(修剪($鏈接));'而不是'$ doc- > loadHtml(file_get_contents($ link));'。 – nickb
閱讀錯誤消息,您提供了錯誤的鏈接,並且沒有要打開的文件。永久鏈接不一定是指向文件的鏈接。另外,loadHTMLFile()獲取文件,不接受字符串。 – adeneo
鏈接是正確的...我已經多次檢查過。永久鏈接是一個網址。 –