Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Thanked 0 Times in 0 Posts

    Question link to a word from a text file

    Hello, this is my firts post on this forum, and I speak spanish, so if my english isn't good, just.. sorry

    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..

    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

  • #2
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Sydney, Australia
    Thanked 1 Time in 1 Post
    Welcome to the forums!

    I believe this is what you want to do --

    PHP Code:
    $filename "vars.txt";
    $handle fopen($filename"r");
    $contents fread($handlefilesize($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 --

    PHP Code:
    for ( $i 0$i count($vars);  $i++ ) { 
    "<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 --

    Last edited by Mhtml; 03-31-2004 at 10:06 AM.
    Omnis mico antequam dominus Spookster!


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts