FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

How can I import text into a .html file from a .txt file?

 


Relentless
Hi, i want to be able to update text on my site without having to edit the HTML page.

I want to avoid using php or Iframes...

I thought you could do it with javascript...

Any ideas?

But if php is recomended please post the script if you have one..

Advanced Thanks Dan
badai
php is preprocessor, that is, once it send the request to your browser, it's done doing it job. you need to send another request if you want it to update the text.

if you use iframe, you can use javascript just to request the text file without server sending the whole page again.

just give a name to your iframe

Code:
<iframe name="my_iframe" src="the_first_text_file_to_display.txt" .....


then use script to change the src

Code:
top.frames['my_iframe'].location='next_text_file.txt';


if the frame is nested in another frame

Code:
top.frames['first_iframe'].frames['second_iframe'].location='next_text_file.txt';
sonam
Quote:
Hi, i want to be able to update text on my site without having to edit the HTML page.


Hmmmm, without little bit more information it is not easy to answer on your question. Did you want to update this page ones in the day, ones in the week or every hour. Did you need some type of styling, etc. If you want PHP then you can simple to use include function. Just put this script on place (div, td, p, etc.) where you want to see your txt file.

Code:
<?php
include_once("some.txt");
?>


Sonam
leontius
Why don't you install a CMS? In cPanel, access the menu called "Fantastico". If you click on it, it will list some free PHP applications you can use. Fantastico can install them automatically for you, just choose the one you want and provide the necessary details. Choose the Content Management ones - Drupal, Joomla, Xoops etc. or Blogs like Wordpress.
Relentless
badai Sorry but as I said... I do not want to use iFrames...
Cheers anyway....
--------------------------------------------------------------------------------------
leontius wrote:
Why don't you install a CMS? In cPanel, access the menu called "Fantastico".


I don't have cPanel I have DA from server 2.
--------------------------------------------------------------------------------------

Sonam Thanks for your reply... I did find a php script for what I wanted... I am able to inport what ever i like from the .txt file even my whole navigation bar for all the pages... handy if I want to add a link...
Here is the hode if it's handy to others...
Code:
<?php
$filename="TEXTFILE.txt";
$handle=fopen($filename,"r");

$contents=fread
($handle,filesize($filename));

echo($contents);
?>

Hope this helps other with a similar problem...

Daniel...
sonam
Actualy I don't like too often to use fopen function. Include is more simpler, less errors and use less memory. You can write whatever you want (size, color, class, links, part of html, JavaScript, etc in one txt file. Inlude function just copy/paste this file direct in html. On my site I am using this for ads (AdSense too), menu and some other stuff. When I want change something I need just to change few lines in one txt file.

Sonam

BTW if you using fopen function I am recomend to use fclose function on the end of script. Wink
AOP Web Development
you could also use... file_get_contents('txtfile here');
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.