1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help with PHP script (very easy for programmers)

Discussion in 'PHP & Perl' started by IntensE, Dec 20, 2013.

  1. IntensE

    IntensE Power Member

    Joined:
    Aug 19, 2008
    Messages:
    765
    Likes Received:
    656
    Occupation:
    Cashing in
    Location:
    thugz mansion
    Hello, I need to make a page like this one: http://mnemotechnics.org/3.1415926/t/words3.php

    But I need to do it with words in a different language and also input the number of words to display.

    So far, I made this code:

    Code:
    <?php  
    $filename = $_SERVER["DOCUMENT_ROOT"].'/test/words.txt'; 
    $number = $_POST['number'];
    if ($fileContents = file($filename)) { 
     shuffle($fileContents); 
    
    ?>
    
    <form action="." method="POST">
    <br><br>How many words to show? <input type="text" name="number"><br>
    <input type="submit" value=" Enter ">
    </form>
    
    <h2>List of words:</h2><br >
    <?php
    for ($i = 0; $i < $number; $i++) { 
      print($fileContents[$i]. '<br />'); 
     } 
    } else { 
     die('Could not get contents of: ' . $filename); 
    } 
    
    ?>
    This code displays the words ok, but they are not in a list and I need to make it like the website above with words numbered like:
    1. word1
    2. word2
    3. word-etc

    Any help ?
     
  2. tdivan

    tdivan Newbie

    Joined:
    Aug 12, 2013
    Messages:
    46
    Likes Received:
    16
    you need to break out into HTML you have already done this in your code with
    '<br />'

    so you just need to put in a <ol> ordered list in your PHP code
    you already have a looping for statement you just need to add your HTML elements
     
    • Thanks Thanks x 1
  3. IntensE

    IntensE Power Member

    Joined:
    Aug 19, 2008
    Messages:
    765
    Likes Received:
    656
    Occupation:
    Cashing in
    Location:
    thugz mansion
    thanks a lot, I figured it out !