我正在 WordPress 中编辑 wp-comments-post.php 文件。我尝试在非 wordpress 程序中运行以下代码,它返回了http://mysmallwebpage.com/网站中的所有 URL。但是当我将以下代码放入 wp-comments-post.php 文件时,DOMDocument
似乎不起作用。如果我在这里做错了什么,请告诉我。
if ( 'abc' == $comment_content )//if the comment page only have the letters abc
{
$html = file_get_contents("http://mysmallwebpage.com/");
$dom = new DOMDocument;
@$dom->loadHTML($html);
$links = $dom->getElementsByTagName('a');
foreach ($links as $link)
{
$returnLink = $link->getAttribute('href');
if (strpos($returnLink, 'http') === 0) //To check if the line contain the keyword 'http'
{
$returnLink = "<a href=\"$returnLink\">$returnLink</a>";
array_push($URL_List, (string)$returnLink);
//I inserted the following wordpress termination code to see if it contain at least one element
wp_die( __('<strong>ERROR</strong>: Program Reached here! ') );
}
}
//if I put wp_die( …… ), It works in this location. Just not above.
}