0

我在 Windows 7 64 位机器上的 XAMPP 环境中工作。我安装了 Apache 2.4 服务。我遇到的问题让我困惑了大约一天。

到目前为止,我的 php 文件都已按预期执行。最近,我创建了一个文件,该文件以以下内容开头:

    function get_web_page($url,$attempt=1){
        if($attempt <4){
            $options = array(
                CURLOPT_RETURNTRANSFER => true,     // return web page
                CURLOPT_HEADER         => false,    // don't return headers
                CURLOPT_FOLLOWLOCATION => true,     // follow redirects
                CURLOPT_ENCODING       => "",       // handle all encodings
                CURLOPT_USERAGENT      => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120427 Firefox/15.0a1", // who am i
                CURLOPT_AUTOREFERER    => true,     // set referer on redirect
                CURLOPT_CONNECTTIMEOUT => 30,      // timeout on connect
                CURLOPT_TIMEOUT        => 30,      // timeout on response
                CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
            );
            $ch      = curl_init( $url );
            curl_setopt_array( $ch, $options );
            $content = curl_exec( $ch );
            $err     = curl_errno( $ch );
            $errmsg  = curl_error( $ch );
            $header  = curl_getinfo( $ch );
            curl_close( $ch );

            if($err == 0){
                return $content;
            }else{
                return get_web_page( $url, $attempt + 1 );
            }
        }else{
            return FALSE;
        }
    }

一个检索网页的简单函数,它也不回显任何内容。但是当我在浏览器中访问这个页面时(此时它只定义了一个函数,没有其他任何东西),它会将第一个“=>”实例之后的所有内容打印到页面上(不带引号)。我不明白为什么会这样。我在同一目录中的所有其他 php 文件都按预期运行。

请帮助我了解为什么会发生这种情况以及我应该采取哪些步骤来解决它。

4

1 回答 1

2

Look at the source of the page given to your browser and you'll probably see the entire php source in plaintext. It's only rendering what's after the first => because that's likely the first closing > it finds after the opening < in <?php. The first part doesn't render because your browser thinks it's inside some strange HTML tag.

Check your apache config, because it's not routing requests for *.php pages through the PHP interpreter.

于 2012-12-07T17:29:51.107 回答