Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9247677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:47:27+00:00 2026-06-18T09:47:27+00:00

The code in my .php file is displayed as it is on the browser.

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:47:28+00:00Added an answer on June 18, 2026 at 9:47 am

    My comment as an answer:

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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this code in a php file on my VPS server: <?php $url =
I am running some PHP code to my browser. If I navigate to a
I'm new to PHP. I installed XAMPP and have Apache running. I created helloworld.php
I'm happy with the php code I'm currently using to display the file contents
The code chokes at fopen(): <?php ini_set('display_errors',1); error_reporting(E_ALL); $fp = fopen(/path/to/file/some_file.txt,a) or die(can't open
I'm writing code in PHP that requires including a config.php file depending on the
I am writing a PHP code that creates another PHP file with fopen and
I am having a php file which executes some code to generate a html
I have this code which will include template.php file from inside each of these
I have some setup code in my functions.php file that sets permalinks and adds

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.