Hosting Solutions
mobile_logo Table of Contents

Random Array Items From Flat Text File Database Tutorial

In this exercise we put several built in PHP functions to use in order to turn an idea into an application. We take the described logic and translate it into script by accessing knowledge we have of PHP's built in functions and applying them. Some people have to use text files in place of MySQL for data management so this lesson is another one that deals with text file data handling for dynamic purposes on a website. <?php $text = file_get_contents('flatFileDB.txt'); $textArray = explode("\n", $text); $randArrayIndexNum = array_rand($textArray); $randPhrase = $textArray[$randArrayIndexNum]; ?> <html> <body> <h2><?php echo $randPhrase; ?></h2> </body> </html> flatFileDB.txt Hello and Welcome! Hi how are you today? Welcome Pilgrims! Hey There Weenis! Howdy Partner! Hola Amigos! Hallo Vrienden! Bonjour Les Amis! Cairde Dia duit! Cras Venenatis!

PHP Videos

Array Programming

Dynamic Grid Output Programming Array Data TutorialReplace Characters with Emoticon Icons Array TutorialRandom Array Items From Flat Text File Database TutorialBad Word Filter Function and Harmful Character String Array ReplaceFind Value in Array Search Needle in Haystack TutorialMultiple Files Simultaneous Upload Array Programming TutorialBrowser and Operating System Detect Array Script