hi i need this text box www.crazybunny.info to load from a .txt file is it possible to do so if so how do i do. please could someone help with maybe a bit of source code or something. i would like it so a .txt file in the public_html directory to be loaded and have the contents loaded into my news text box on my homepage, as this would be a much easier way for me to upload new news into the news box without having to edit the page then upload it.
is it possible to get a html text box to load a .txt file?
I don't know if this is what you are looking for or not, but you can load the contents of a file (that resides on the server, or other networked area) into a variable in PHP and then print the contents of this variable (ie the file) to the screen.
The code is pretty self explanatory: The first line (<?php) starts the php script, the second line declares a variable ($string) and sets the contents of the specified open file opened with fopen (opens the file specified in the parentheses - in this case as read only.). The 'echo $string' line is printing the contents of the $string variable (the text file contents that are store within it) to the screen.
This is pretty universal and can be used and formatted however you see fit. Luckily, Firhost has PHP installed, so there is really nothing else you need to do other than include this script in your file and make sure that the file is named *.php (ending with 'php'). The php file can contain a mix of HTML and PHP. Also, html markup can be included in the text file you are importing and will be rendered as html once echoed within the webpage.
-Matt
| Code: |
|
<?php $string = fopen("textfile.txt","r"); echo $string; ?> |
The code is pretty self explanatory: The first line (<?php) starts the php script, the second line declares a variable ($string) and sets the contents of the specified open file opened with fopen (opens the file specified in the parentheses - in this case as read only.). The 'echo $string' line is printing the contents of the $string variable (the text file contents that are store within it) to the screen.
This is pretty universal and can be used and formatted however you see fit. Luckily, Firhost has PHP installed, so there is really nothing else you need to do other than include this script in your file and make sure that the file is named *.php (ending with 'php'). The php file can contain a mix of HTML and PHP. Also, html markup can be included in the text file you are importing and will be rendered as html once echoed within the webpage.
-Matt
Related topics
