Forum Moderators: coopster

Message Too Old, No Replies

whats wrong with this code

         

botmog

2:20 pm on Dec 17, 2003 (gmt 0)

10+ Year Member



.html file, doesn't read from the text file like i want it to, this is probably so simple...sorry im new.

<html>
<head>
<title>Untitled Document</title>
<style type="text/css">
<!--
table { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9px; color: 920000; border-color: 920000 920000 920000 #920000; border-style: dotted; border-top-width: thin; border-right-width: thin; border-bottom-width: thin; border-left-width: thin}
-->
</style>
</head>
<body bgcolor="#F9F9F9" text="#4A4A4A" link="920000" alink="920000" vlink="920000">
<div align="center">
<br>
<table width="214" height="114" border="0" name="t1" bordercolor="920000">
<tr>
<td width="214" height="114" align="left" valign="bottom">
<center><b>thesunisleaving.t35.com</b></center>
<br>
<?php
$file = "file.txt";
if($fp=fopen($file, "r+"))
{
while($line=trim(fgets($fp)))
{
$text .= $line;
}
echo str_replace("\n", "
", $text);
}
else
{
echo 'Unable to open file';
?>
</td>
</tr>
<tr>
<td height="18" align="left" valign="middle">&nbsp; </td>
</tr>
</table>
</div>
</body>
</html>

coopster

3:12 pm on Dec 17, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, botmog!

Are you getting anything at all, or only one line?

botmog

9:32 am on Dec 18, 2003 (gmt 0)

10+ Year Member



hey, um im getting nothing...

botmog

9:36 am on Dec 18, 2003 (gmt 0)

10+ Year Member



um actually, when saved as a html file, it displays all the html part of the page yet does not output the text from the text file.

Mr_Brutal

11:16 am on Dec 18, 2003 (gmt 0)

10+ Year Member



Hi there botmog,

Just a quick thought as not got much experience with php but you have named the file .php or configured your webserver to treat html files as php.

Otherwise it's not gonna parse the php right?

botmog

11:51 am on Dec 18, 2003 (gmt 0)

10+ Year Member



whether i save this file as a .php or .html

if i save it as .php
-i get absolutely nothing

if i save it as .html
-i can see the html parts of the page yet the text file read (php part) does not show.

:/ ive spent like 3 hours on this over tonight and last night and i cant get the bloody thing to work.....very stressful!

slade7

2:19 pm on Dec 18, 2003 (gmt 0)

10+ Year Member



If your host supports php, you should absolutely, no matter what see the line "thesunisleaving.t35.com" no matter whether you have saved the file as .php or .html

But if you are getting nothing when the file is saved with a .php extension, it sounds like your host doesn't support php.

ergophobe

4:23 pm on Dec 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just to reiterate - do you know you have PHP support? The best way to find out is as follows:

create a file called info.php and it should contain the following three lines and nothing but (everything between but not including the "begin" and "end"):

begin file
<?php
phpinfo();
?>
end file

Then open up that file. If that works, go back to your original file and outside any conditional statements, just put a line like

echo "PHP is working";

If that works, put another one after the if statement

echo "File successfully opened";

Keep doing that and you should see where the problem is right quick.

You said you were a real beginner - you're not working locally and opening the PHP file straight in your browser without going through the server are you?

Tom

botmog

3:19 am on Dec 20, 2003 (gmt 0)

10+ Year Member



im sure my host has php support, i had the script working originally but when i added html to format the look of the page it didnt work, and then when i tried to revert back to the old way of doing i couldnt get it to work anymore.

ergophobe

4:50 am on Dec 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



did you go through the testing sequence I suggested (phpinfo and so on)? If so, how far did you get?

Tom