.php文件在屏幕上显示代码。 我该如何解决?

The code in my .php file is displayed as it is on the browser. I'm running apache 2.4 with the XAMPP server and adding <?php phpinfo(); ?> works so I'm guessing the php version 5.4 is working fine too. My index.php file looks like this:

    <!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Something</title>
    </head>
    <body>
        <?php 
        include 'json_encoded.php'; 
        ?>
        <script type='text/javascript'>

            /* @var $image_urls type */
            var jsarray = ["<?php echo join("\", \"", $image_urls); ?>"];
            //document.write(getlength(jsarray));
        </script>
    </body>
</html>

and my json_encoded.php file looks like this:

<?php
        header("Content-type: text/javascript");
        error_reporting(E_ALL);

ini_set('display_errors', '1');
        $url = 'some url';

        $var = fread_url($url);
            preg_match_all ("@((http://web)([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@", 
                            $var, $matches);

            $matches = $matches[1];
            $image_urls = array();
            foreach($matches as $var)
            {   
                $var1 = str_replace("/med/", "/lg/", $var);
                $image_urls[] = $var1;
            }


        // The fread_url function allows you to get a complete
        // page. If CURL is not installed replace the contents with
        // a fopen / fget loop

            function fread_url($url,$ref="")
            {
                if(function_exists("curl_init")){
                    $ch = curl_init();
                    $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; ".
                                  "Windows NT 5.0)";
                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
                    curl_setopt( $ch, CURLOPT_HTTPGET, 1 );
                    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
                    curl_setopt( $ch, CURLOPT_FOLLOWLOCATION , 1 );
                    curl_setopt( $ch, CURLOPT_FOLLOWLOCATION , 1 );
                    curl_setopt( $ch, CURLOPT_URL, $url );
                    curl_setopt( $ch, CURLOPT_REFERER, $ref );
                    curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
                    $html = curl_exec($ch);
                    curl_close($ch);
                }
                else{
                    $hfile = fopen($url,"r");
                    if($hfile){
                        while(!feof($hfile)){
                            $html.=fgets($hfile,1024);
                        }
                    }
                }
                return $html;
            }
?>

and my output when running localhost:... looks like this

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Today's Front Pages</title>
    </head>
    <body>
        <script type='text/javascript'>

            /* @var $image_urls type */
            var jsarray = [...contents of array];
                        //document.write(getlength(jsarray));
    </script>
</body>

</html>

Does anyone know what I'm doing wrong? I saw several posts on the topic but they all indicated that php wasn't installed correctly but that's not my case. Incase it's of any importance, I'm using NetBeans 7.2 as my IDE.

Any help is appreciated. Thanks!

My comment as an answer:

Remove header("Content-type: text/javascript"); from json_encoded.php

Why using

 header("Content-type: text/javascript");

In your json_encoded.php if you want to include it in your index.php?!

  1. It is not JSON actually.
  2. When you include an other php file you are going to execute in too.