View Full Version : link to a word from a text file

03-31-2004, 04:27 AM
Hello, this is my firts post on this forum, and I speak spanish, so if my english isn't good, just.. sorry :thumbsup:

Well.. I need to do a single script but I dont know how to start with that.

So the script is anything like:
- I could put manually some words in a text file (file.txt)
- From a PHP file take these words, and make a link to a file with the SAME name of that word...
- On the new page... the variable must be at the title of the page <title>$var</title> and at the body ... <body> $var</body>

i dont know basically how to make the script in PHP to take the words from the text file and make a link over the word TO $var.php

I mean...
in file.txt i have;

and in the index.php..
shoes (shoes.php)

so... when anybody click on "shoes" appears on a page called "shoes.php" with the title "shoes" and in the body "shoes".

Sorry for the confusion :P

03-31-2004, 10:03 AM
Welcome to the forums! :):thumbsup:

I believe this is what you want to do --

$filename = "vars.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));

/*The variable $contents, has well.. the contents.. */

$symbol = ",";

$vars = explode( $symbol, $contents );

$vars now contains each word, so you can either run through the array and echo out each one or you can pick specific indexes to print ... if you want to go for the first option you would simply do this --

for ( $i = 0; $i < count($vars); $i++ ) {

echo "<a href=\"".$vars[i].".php\">".$vars[i]."</a><br/>" ;


Hopefully that wasn't to confusing for you ... if it is just ask and I will try to explain a little further. :)

You may notice the $symbol variable, this allows you to decide on how you are going to layout your text file! If you leave the ',' in there, you can have your file like --

var1,var2,var3 ... etc

You could change $symbol to \n and then you could have it on each line like this --