PHP Random Array Content From Flat Text File Database Tutorial

PHP Random Array Content From Flat Text File Database Tutorial

Listening Video

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.
Lesson Code
<?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>

<!-- Below is the content inside of 'flatFileDB.txt' for referencing -->
<!--
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! 
-->

Related Posts :

  • cue cue CSS cue Property The CSS cue-after , cue-before and cue … Read More...
  • elevation elevation CSS elevation Property The CSS elevation property is part of CSS aural… Read More...
  • direction direction CSS direction Property The CSS direction property is used to specify t… Read More...
  • counter-reset counter-reset CSS counter-reset Property The CSS counter-reset property is used … Read More...
  • cursor cursor CSS cursor Property The CSS cursor property is used to change the cursor … Read More...

0 Response to "PHP Random Array Content From Flat Text File Database Tutorial"

Post a Comment