Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » General Discussions » General Discussion » html news page fed from a text file?
html news page fed from a text file? [message #387326] Thu, 21 May 2009 09:31 Go to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
Is there any way to display text on a website, but have the website read the text from a text file?
The site is written in HTML, but can contain script tags.

It's just for a stupid work project that I need to set-up, then leave in the hands of someone else.

If anyone could enlighten me, that would be cool. Running on IIS.

I'm really not a web guy at all, so if you do feel like helping, please paste the code here too.

I am hoping it'll be something simple, nothing fancy really needed.



Re: html news page fed from a text file? [message #387363 is a reply to message #387326] Thu, 21 May 2009 13:41 Go to previous messageGo to next message
Goztow is currently offline  Goztow
Messages: 9745
Registered: March 2005
Location: Belgium
Karma: 14
General (5 Stars)
Goztoe
Maybe start with this: http://www.tizag.com/phpT/fileread.php (tutorial = google result for php function fopen / fread).

You can find me in The KOSs2 (TK2) discord while I'm playing. Feel free to come and say hi! TK2 discord

[Updated on: Thu, 21 May 2009 13:42]

Report message to a moderator

Re: html news page fed from a text file? [message #387368 is a reply to message #387326] Thu, 21 May 2009 13:53 Go to previous messageGo to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
Forgive me, I am able to write simple HTML pages, I have never used PHP. I am unsure that the server supports PHP, but if it does, how do I insert PHP code into an HTML page?


Re: html news page fed from a text file? [message #387371 is a reply to message #387368] Thu, 21 May 2009 14:39 Go to previous messageGo to next message
futura83
Messages: 1285
Registered: July 2006
Location: England
Karma: 0
General (1 Star)
Viva la Resistance!
reborn wrote on Thu, 21 May 2009 21:53

Forgive me, I am able to write simple HTML pages, I have never used PHP. I am unsure that the server supports PHP, but if it does, how do I insert PHP code into an HTML page?




Put the PHP code after:

<?php



and before

?>



To use HTML within PHP use the code:


echo "<HTML CODE GOES HERE>";



Although, you won't be able to use any " in the html code, but you can use ' instead to open and close the echo bit.


Edit:


Use this code to see if your server works with PHP:
<?php 
echo "Hello world!"; 
?>



edit2:



<?php
function file_input($filename)
{
   $fo = fopen($filename, 'r');
   $read = fread($fo, filesize($filename));
   fclose($fo);
   echo $read;
}
?>



That should put the contents of the file into the page, exactly as the file is written.


Put that ANYWHERE in your page and then do:

<?php file_input('test.txt'); ?>


Replacing test.txt with the right filename.

That way you can call it multiple times in one page with different files without having to copy and past the same text.

even if you don't, you can put the main bit out of the way and call only the funtion where you want it, to make your code look tidier.


Yes, i just manipulated the info from what goztow posted but i wanted to feel useful.


This is a signature. Reading this is wasting your time.

[Updated on: Thu, 21 May 2009 15:22]

Report message to a moderator

Re: html news page fed from a text file? [message #387412 is a reply to message #387326] Thu, 21 May 2009 22:31 Go to previous messageGo to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
Thankyou very much for your help guys. Going into the office soon, hopefully it'll work. In Love


Re: html news page fed from a text file? [message #387418 is a reply to message #387326] Fri, 22 May 2009 00:08 Go to previous messageGo to next message
Goztow is currently offline  Goztow
Messages: 9745
Registered: March 2005
Location: Belgium
Karma: 14
General (5 Stars)
Goztoe
I figured a code monkey like u knew the basics of php. Tx for explaining in detail, roshambo.

You can find me in The KOSs2 (TK2) discord while I'm playing. Feel free to come and say hi! TK2 discord
Re: html news page fed from a text file? [message #387420 is a reply to message #387326] Fri, 22 May 2009 00:22 Go to previous messageGo to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
The following shows no changes on the page at all, is it right? Or does the server not support PHP? I am an admin on the server at work, so I can install it if needed...


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>news page feed</title>
</head>
<body>
<center>
<b>
<big>
Some place holder text
</big>
<br />
<br />
</b>
</center>
<center>
<TABLE BORDER="0" cellpadding="0" CELLSPACING="0">
<TR>

<TD WIDTH="1007" HEIGHT="624" BACKGROUND="images\background.jpg" VALIGN="top">
<br />
<big>
News Announcement!<br />
</big>
<br />
<?php
function file_input($newsfeed.txt)
{
   $fo = fopen($newsfeed.txt, 'r');
   $read = fread($fo, filesize($newsfeed.txt));
   fclose($fo);
   echo $read;
}
?>
<?php file_input('newsfeed.txt'); ?>

<br />
<big>
<A href="newsletters.htm">Access the monthly message</A><br />
<br />
<A href="ProductInfo.htm">Access the product info page</A><br />
<br />
</big>
</TD>
</TD>
</TR>
</TABLE> 
</center>
<IMG SRC="images\logo.png" ALT="logo image" ALIGN=RIGHT>

<br />
<br />
<center>
<small>
If there are any problems regarding this site, broken links, typo's or you wish to add content etc etc, please <A href="mailto:myanus@butthole.com">email me</A>.
</small>
</center>

</body>
</html>





Re: html news page fed from a text file? [message #387421 is a reply to message #387326] Fri, 22 May 2009 00:54 Go to previous messageGo to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
Something is weird with my thread, I have to log out to see Goztows replies o.0
Also, did you mean insert_name_here rather then roshambo? I cannot see a post from Roshambo and was wondering if he did post but I cannot see it for some reason :-/

I havn't got a clue about php, although looking at the code posted it seems to be object orientated. I've always been lucky with website stuff, MP-Gaming is administered by Oxi, I have extremely little to do with any thing related to the site itself.

It's actually embarrassing how little I know about it really.



Re: html news page fed from a text file? [message #387427 is a reply to message #387326] Fri, 22 May 2009 01:57 Go to previous messageGo to next message
Goztow is currently offline  Goztow
Messages: 9745
Registered: March 2005
Location: Belgium
Karma: 14
General (5 Stars)
Goztoe
Oops, I took insert_name for roshambo, as I was posting from my mobile.

Ermmm did u try the "hello world" code insert_name posted, to check if php is enabled?


You can find me in The KOSs2 (TK2) discord while I'm playing. Feel free to come and say hi! TK2 discord
Re: html news page fed from a text file? [message #387432 is a reply to message #387326] Fri, 22 May 2009 02:49 Go to previous messageGo to next message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma: 0
General (3 Stars)
Yeah I tried that, but nothing really happened. I ran the installer for PHP off there site. I probably need to configure something, but I've never had to do it before. Is there soemthign I am missing about installing PHP then configuring IIS to allow PHP code to run or something?
I hate this, at least with C I have half a clue what I'm doing, I really don't like this at all.

I really really do appreciate the help. Smile



[Updated on: Fri, 22 May 2009 02:49]

Report message to a moderator

Re: html news page fed from a text file? [message #387435 is a reply to message #387326] Fri, 22 May 2009 04:05 Go to previous messageGo to next message
Omar007 is currently offline  Omar007
Messages: 1711
Registered: December 2007
Location: Amsterdam
Karma: 0
General (1 Star)
Does it show this as plain text on the page??
<?php
function file_input($newsfeed.txt)
{
   $fo = fopen($newsfeed.txt, 'r');
   $read = fread($fo, filesize($newsfeed.txt));
   fclose($fo);
   echo $read;
}
?>
<?php file_input('newsfeed.txt'); ?>


Or do you just have a total blank page??


NOTE: Guess you already did this Razz
Save it as filetype *.php instead of *.html Tell Me

NOTE2: If you don't have PHP in your IIS server, get it here (IIS 7) http://php.iis.net/

Or this if you have 5 or 6 http://www.iis-aid.com/articles/how_to_guides/installing_php_5_on_iis_in_5_simpl e_steps


http://tiberiumredux.omarpakker.nl/Old Unused Parts/Plaatjes/PromoteBanner_Hades_small.jpg

[Updated on: Fri, 22 May 2009 04:07]

Report message to a moderator

Re: html news page fed from a text file? [message #387441 is a reply to message #387326] Fri, 22 May 2009 06:18 Go to previous message
danpaul88 is currently offline  danpaul88
Messages: 5795
Registered: June 2004
Location: England
Karma: 0
General (5 Stars)
I used the following tutorial to install and configure PHP on IIS 7, worked OK first time for me, obv. depends on your version of IIS though.

http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis -70


http://steamsignature.com/card/1/76561197975867233.png

[Updated on: Fri, 22 May 2009 06:19]

Report message to a moderator

Previous Topic: WolframAlpha - Answers your questions
Next Topic: 'Tiberium' First Person Shooter Features
Goto Forum:
  


Current Time: Wed Feb 12 08:51:53 MST 2025

Total time taken to generate the page: 0.01455 seconds