-1

だから私はこの検索スクリプトをXAMPPでローカルに実行しようとしてきましたが、それが私が得ているエラーです。ヒントはありますか? 私はプログラミングについてあまり知らないので、なぜ私が尋ねているのか、私はスクリプトを公開ソースから入手し、ローカルにセットアップしようとしていました.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>Search Engine</title>
        <style type="text/css">
            .footertext{
                position:center;
                bottom:0;
            }
            body {
                background-color: #202020;
            }
            body,td,th {
                color: #CCC;
                font-family: Verdana, Geneva, sans-serif;
            }
            .searchbox {
                font-family: Verdana, Geneva, sans-serif;
                font-size: 18px;
                color: #CCC;
                background-color: #333;
                border: 1px solid #CCC;
                padding-left: 10px;
            }
        </style>
    </head>
    <body>
        <div align="center">
            <a href=""><img border="0" src="" alt ="logo"></a>
            <br>
            <br><a href="/dblookup.php/"><b><u>Search Again</u></b></a>
            <br>How to use: <br>Input search term and click search.
        </div>

        <div align="center">
        <?php

        $fname = strlen(htmlspecialchars($_POST['text']));

        if (isset($_POST['text'])){
            $directory = "";

            //get all image files with a .jpg extension.
            $images = glob($directory . "*.txt");

            //print each file name
            foreach($images as $image)
            {
                if($fname<3)
                {
                    echo "You must have atleast 4 characters in your search, Sorry.";
                    return;
                }

                $file = $image;
                $searchfor = $_POST['text'];

                // the following line prevents the browser from parsing this as HTML.
                // get the file contents, assuming the file to be readable (and exist)
                $contents = file_get_contents($file);
                // escape special characters in the query
                $pattern = preg_quote($searchfor, '/');
                // finalise the regular expression, matching the whole line
                $pattern = "/^.*$pattern.*$/mi";
                //require "sanitize.php";

                // search, and store all matching occurences in $matchess
                if(preg_match_all($pattern, $contents, $matches)){
                    echo "<br><br>Found matches in $file:<br />";

                    //$nigga = array_map("htmlspecialchars", $matches);
                    //vv this part
                    $gud = implode("\n", $matches[0]);
                    //#####################^ htmlspecialchars($matches[0]) -> But it doesnt output anything..
                    //#This part ^^
                    echo nl2br(htmlspecialchars($gud));
                }else{
                    echo "";
                }
            }
        } else {
        ?>
        </div>
        <form action='' method='post'>
            <div align="center">Search: <br><input name='text' type='text' class="searchbox"> 
                <input type='submit' class="searchbox" value='Search'>
            </div>
        </form>

        <? } ?>
        <div class="footertext">
            <br><br><br>
            <center>Lookup: <a href="">Lookup</center>
        </div>
    </body>
</html>
4

3 に答える 3

4

PHP の設定でshort_open_tagsが許可されていないようです。

次の行を置き換えます。

<? } ?>

と:

<?php } ?>

phpfiddle での修正後のコードの作業バージョンは次のとおりです: http://phpfiddle.org/main/code/8sm-b3g

于 2013-09-10T04:11:12.960 に答える
3

注: PHP の短いタグは、新しいバージョンでは非推奨です。

この行を変更

<? } ?>

<?php } ?>
于 2013-09-10T04:11:03.603 に答える
0

PHP の設定で、ディレクティブ short_open_tags が有効になっていません。このディレクティブが有効になっている場合、PHP はタグで実行できます: <? ?>. したがって、エラーが表示され、必須である<? ?>必要があります<?php ?>。ファイルを で実行する場合は、ファイルに<? ?>移動しますphp.ini。次の行のコメントを外します。

short_open_tag = Off

次のように変更します。

short_open_tag = On

そして、あなたのコードは機能します。

于 2013-09-10T07:15:13.783 に答える