Jump to content

PHP read/echo problem


RAWKHIGH
Go to solution Solved by davidannis,

Recommended Posts

This is my first time posting sorry if anything is wrong.

 

attached are my files in question but i don't know what is wrong. I want to show info from a .txt file or something similar within the website I'm working on. In AS3 it was easy to read and use an xml file but within html/php i cant remember. i want to be able to have to have the people im making the site for to be able to just update the text file and it will update the certain part of the site with the new information. Currently for some reason its commenting out part of my php code that i believe should read and echo the lines of the text file.

 

this is the php code:

<div id="home">
                <h3>Updates From the Staff</h3>
                <p>
                    <?php
                        $file = fopen("news.txt", "r") or exit("Unable to open file!");
                        while(!feof($file))
                            {
                            echo fgets($file). "<br>";
                            }
                        fclose($file);
                    ?>
                </p>
            </div><!-- End Nav Home -->
 
this is what shows when i inspect element with chrome:
 
<!--?php
                        $file = fopen("news.txt", "r") or exit("Unable to open file!");
                        //Output a line of the file until the end is reached
                        while(!feof($file))
                            {
                            echo fgets($file). "<br-->
its commenting out everything till the line brake and just showing
"; }  fclose($file);
 
If someone could help me that would be amazing if not thats ok aswell. 
Edited by Zane
Link to comment
Share on other sites

looks to me like your server isn't setup to parse your file extension as a php file. When a file is requested, the server doesn't automatically go through the file looking for relevant script tags to parse. You must set it up to run it through things like php or perl or w/e based on the file extension. For example, if that code is in like somefile.html (I did not download your zip to look), the server's default settings are not setup to run an html file through the php interpreter.

Link to comment
Share on other sites

  • Solution

AFAIK you need to serve it through a server if you want to mix html and php and display it in a browser. There are local servers you can install on Windows, Linux, and Mac. Google WAMP, LAMP, or MAMP to get apache, MySql, and PHP all bundled together and easy to install on your OS.

Link to comment
Share on other sites

I haven't used komodo editor but doing a quick 1m glance at their site it looks like it's just an editor, doesn't have a server and php built into it to actually evaluate php code. As davidannis said, look into using something like WAMP or XAMPP. Komodo may even have a way in its settings to point to one of those for preview once they are installed (but I'll leave that research up to you)

Link to comment
Share on other sites

thank you everyone for the help im going to dl xampp and get back to work. Thank you very much again to everyone for the help i feel kinda stupid for forgetting something so simple but now i can get back to work and show them an update. 

 

again because I'm new to the site and all is there anything i have to do to close this topic and say its finish?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.