TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-22-2009, 09:13 PM   #1 (permalink)
The Wanderer
 
Join Date: Feb 2009
Posts: 9
Thanks: 0
chikooo is on a distinguished road
Default how do i display on a php file the content of a text document

is there some kind of script that will let me display text from a text text.txt document on a single php file.
chikooo is offline  
Reply With Quote
Old 02-22-2009, 10:05 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,267
Thanks: 90
Wildhoney is on a distinguished road
Default

Do you mean something like file_get_contents?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 02-23-2009, 01:58 PM   #3 (permalink)
The Wanderer
 
Join Date: Feb 2009
Posts: 9
Thanks: 0
chikooo is on a distinguished road
Default

yeah something like that i think
example: i have a php file named"index.php" on the same directory i have a text document called "text.txt" when i visit the index.php page it gets a random quote from the text.txt file. this is the php code that i put on the index.php file for it to display a random text.txt file
<?php
// En: Begin PHP Code / Fr: Debut code PHP
/************************************************** ****************************\
* Random Text Version 1.0 *
* Copyright 2000 Frederic TYNDIUK (FTLS) All Rights Reserved. *
* E-Mail: tyndiuk@ftls.org Script License: GPL *
* Created 02/28/2000 Last Modified 02/28/2000 *
* Scripts Archive at: http://www.ftls.org/php/ *
************************************************** *****************************/
/************************************************** *****************************/
// Necessary Variables:

$RANDOM_TXT_FILE = "text.txt";
// En: Absolute path and name to file contain sentances text.
// Fr: Chemin absolu (complet) et Nom du fichier contenat les phrases.

// End Necessary Variables section
/************************************************** ****************************/

srand((double)microtime()*1000000);

if (file_exists($RANDOM_TXT_FILE)) {
$arry_txt = preg_split("/--NEXT--/", join('', file($RANDOM_TXT_FILE)));
echo $arry_txt[rand(0, sizeof($arry_txt) -1)];
} else {
echo "Error: can't open $RANDOM_IMG_FILE file";
}

// En: End PHP Code
// Fr: Fin code PHP
?>



this is the text on the text.txt file

this is another random text
--NEXT--
this is a random text.
--NEXT--



so i want no to display a random text i want it to be able to see the next text like in another webpage. maybe using that kind of url that is automatically generated by php strings

hope it is more clearly
chikooo is offline  
Reply With Quote
Old 02-23-2009, 04:17 PM   #4 (permalink)
The Contributor
 
hello-world's Avatar
 
Join Date: Feb 2009
Posts: 73
Thanks: 30
hello-world is on a distinguished road
Default

You can do it something like this.
for example you have 20 lines in your text.txt.

Quote:
$rnd = rand(0,19);
$file = file('text.txt');

echo $file[$rnd];

echo end($file);
echo end($file) prints the last line of it.
hello-world is offline  
Reply With Quote
Old 02-23-2009, 05:25 PM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,267
Thanks: 90
Wildhoney is on a distinguished road
Default

Hello World is right, you can do that much simpler and without the --NEXT-- separators. You could use the following. Where the items in the array is your text document loaded with the file function, as in Hello World's example ($aDocument = file('myTextDocument.txt');).

The file function merely creates an array which has been explode'd on the line breaks -- new lines.

php Code:
$aDocument = array
(
    'TalkPHP.com loves Wildhoney',
    'TalkPHP.com loves Salathe',
    'TalkPHP.com loves Village Idiot',
    'TalkPHP.com loves Chikooo'
);

echo $aDocument[array_rand($aDocument)];
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 02-24-2009, 03:25 PM   #6 (permalink)
The Wanderer
 
Join Date: Feb 2009
Posts: 9
Thanks: 0
chikooo is on a distinguished road
Default

but the next quote will be loaded on another web page??
because i want to display all of the quotes on separate pages. not ramdon. in order. in one page a quote on the next page the next quote
chikooo is offline  
Reply With Quote
Old 02-24-2009, 04:01 PM   #7 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,267
Thanks: 90
Wildhoney is on a distinguished road
Default

Set a $_GET variable in the URL and then use that index in conjunction with the $aDocument[] variable.

So, for instance, although insecurely:

php Code:
$iQuoteId = (int) $_GET['quote_id'];
echo $aDocument[$iQuoteId];
Attached Files
File Type: php Quote.php (533 Bytes, 464 views)
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 02-26-2009, 02:07 PM   #8 (permalink)
The Wanderer
 
Join Date: Feb 2009
Posts: 9
Thanks: 0
chikooo is on a distinguished road
Default

i downloaded the file and uploaded to mmy server and it worked just what i wanted but instead of putting the this text
"'TalkPHP.com loves Wildhoney',
'TalkPHP.com loves Salathe',
'TalkPHP.com loves Village Idiot',
'TalkPHP.com loves Chikooo'"

on the php script how do i put it on a separate text.txt file
chikooo is offline  
Reply With Quote
Old 02-26-2009, 03:46 PM   #9 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,267
Thanks: 90
Wildhoney is on a distinguished road
Default

Just substitute the array for the file function and all will be well.
Attached Files
File Type: zip Quote.zip (505 Bytes, 8 views)
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 02-27-2009, 12:00 AM   #10 (permalink)
The Wanderer
 
Join Date: Feb 2009
Posts: 9
Thanks: 0
chikooo is on a distinguished road
Default

that is just what i needed. thank you. you are really good at this. thank you so much
chikooo is offline  
Reply With Quote
The Following User Says Thank You to chikooo For This Useful Post:
Wildhoney (02-27-2009)
Old 03-01-2009, 04:35 PM   #11 (permalink)
The Wanderer
 
Join Date: Feb 2009
Posts: 9
Thanks: 0
chikooo is on a distinguished road
Default

do you know how to take the previous link out on the first page. because on the first page there is not previous quote. and on the last one, how to take the next link out on the last quote
chikooo is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
mail problem galleeandfarel Absolute Beginners 10 02-10-2009 11:17 AM
PHP Compressor Kalle Script Giveaway 8 05-28-2008 12:14 AM
Echoing Text File Rows into Array Display... buildakicker General 11 02-04-2008 06:17 PM
Make Your Own PHP Flash Player Which You Can Pass a File Variable with Preview!!!! thegrayman Tips & Tricks 2 12-11-2007 11:44 PM
Uploading Files with PHP daz Absolute Beginners 3 09-30-2007 06:23 PM


All times are GMT. The time now is 08:40 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design