1

特定の ID を持つ要素だけを取得し、PHP で表示する方法が必要です。私はPHP初心者なので、これまでのところ非常に困難でした。これに似た他の質問はすべて少し複雑すぎたので、誰かが私に説明してくれるかどうか疑問に思っていました.

私が欲しいものをより具体的にするために、マインクラフトサーバーのスペル検索を行っています。私たちのウェブサイトはhttp://pvpzone.org/で、ウィキはhttp://pvpzone.wikispaces.com/にあります。各呪文には wiki にページがあり、「Vanish」のページは pvpzone.wikispaces.com/Vanish です。呪文検索のアイデアは、呪文を探すためのより簡単な方法です。呪文の名前を入力すると、結果が得られます。div 'wiki wikiPage' には、スペル データが含まれています。そのdivだけを取得して表示したい。悲しいことに、呪文を使ってどのような形式のデータベースにも接続できません。それは Wikispaces によってホストされており、許可されていません。

これが明確になったことを願っています。よろしければ詳細をお尋ねください。これが私がこれまでに持っているものです:

<?php
if(isset($_POST['submit']))
{
    $spell=$_POST['spell'];
    $pvpwiki="http://pvpzone.wikispaces.com/";
    $site=$pvpwiki . $spell;
    $submit=true;
}
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>Spell search</title>
    </head>
    <body>
        <form name="spellsearch" id="spellsearchform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
            <input type="text" name="spell" value="<?php if(!isset($_POST['submit'])){echo("Vanish");}?>"></input>
            <input type="submit" value="Search" name="submit"></input>
        </form>
            <?php
                $doc = new DomDocument;
                $doc->validateOnParse = true;
                $doc->loadHtml(file_get_contents($site));
                var_dump($doc->getElementById('wiki wikiPage'));

                if($doc == false && $submit)
                {
                    echo("<br />" . "That is not a spell!");
                }
            ?>
    </body>
</html>

私の問題は、解析エラーが発生することです (警告: DOMDocument::loadHTML() [domdocument.loadhtml]: ID target_editor already defined in Entity, line: 212 in /home/content/d/e/x/dext0459/ html/russellsayshi/phpspellsearch.php の 24 行目 NULL)、助けていただければ幸いです。

4

1 に答える 1

1

表示されるエラー メッセージは単なる警告です。

警告: DOMDocument::loadHTML() [domdocument.loadhtml]: ID target_editor already defined in Entity, line: 212 in /home/content/d/e/x/dext0459/html/russellsayshi/phpspellsearch.php 行 24 NULL

あなたはそれらを無視することができます、彼らはあなたを止めません. Web サイトにそれらが表示される場合は、適切に構成されていません。エラーを表示するのではなく、ログに記録する必要があります。

とにかく、そのライブラリの場合、次の方法でもそれらを無効にすることができます:

libxml_use_internal_errors(true);

HTML をロードする前に呼び出します。そのHTMLところで。そのWebサイトで試したときにエラーは発生しませんでした。

次の間違いは、ID ではなくクラスを探していることです。代わりに ID を探します。

$div = $doc->getElementById('content_view');

コード例全体:

function get_wiki_page_div($page)
{
    $url = sprintf('http://pvpzone.wikispaces.com/%s', urlencode($page));

    $doc = new DOMDocument();
    $doc->validateOnParse = true;
    libxml_use_internal_errors(true);

    $doc->loadHTMLFile($url);

    $div = $doc->getElementById('content_view');

    if (!$div) {
        return false;
    }

    return $doc->saveXML($div);
}

使用法:

<?php
$submit = isset($_POST['submit']);
if ($submit)
{
    $spell  = $_POST['spell'];
    $result = get_wiki_page_div($spell);
}
?>

...


<?php
if ($submit)
{
    echo $result ? $result : '<div>This is not a Spell!</div>';
}
?>
于 2012-09-22T16:35:37.260 に答える