n00b PHP question
I'm looking at the following code:
<?php
[php]
<?php
// En: Begin PHP Code / Fr: Debut code PHP
/******************************************************************************\
* Random Image Displayer Version 1.0 *
* Copyright 2000 Frederic TYNDIUK (FTLS) All Rights Reserved. *
* E-Mail: tyndiuk@ftls.org Script License: GPL *
* Created 02/28/2000 Last Modified 02/28/2000 *
* Scripts Archive at: http://www.ftls.org/php/ *
*******************************************************************************/
/*******************************************************************************/
// Necessary Variables:
$RANDOM_IMG_FILE = "list_img.txt";
// En: Absolute path and name to file contain image URL location.
// Fr: Chemin absolu (complet) et Nom du fichier contenat les URL des images.
// End Necessary Variables section
/******************************************************************************/
srand((double)microtime()*1000000);
if (file_exists($RANDOM_IMG_FILE)) {
$arry = file($RANDOM_IMG_FILE);
// En: load file.
// Fr: charge le fichier.
for($i = 0; $i < sizeof($arry) ; $i++) {
if (preg_match("/\w+/", $arry[$i]))
$good_arry[$j++] = chop($arry[$i]);
# PHP 4.0 arry_push ($good_arry, $arry[$i]);
}
$randval = rand(0, sizeof($good_arry) -1);
$html_result = "";
} else {
$html_result = "error: can't open $RANDOM_IMG_FILE file";
}
// En: End PHP Code
// Fr: Fin code PHP
?>
[/php]
Everything up to the loop makes sense. And the loop in itself makes sense i'm not sure what the preg_match does. I know it's kind of like substring and looked it up on php.net. From what I gather it searches for any character on a keyboard in the string it reads? and if that's the case, what are the /'s for?
Basically can someone explain how the loop works to me?
<?php
[php]
<?php
// En: Begin PHP Code / Fr: Debut code PHP
/******************************************************************************\
* Random Image Displayer Version 1.0 *
* Copyright 2000 Frederic TYNDIUK (FTLS) All Rights Reserved. *
* E-Mail: tyndiuk@ftls.org Script License: GPL *
* Created 02/28/2000 Last Modified 02/28/2000 *
* Scripts Archive at: http://www.ftls.org/php/ *
*******************************************************************************/
/*******************************************************************************/
// Necessary Variables:
$RANDOM_IMG_FILE = "list_img.txt";
// En: Absolute path and name to file contain image URL location.
// Fr: Chemin absolu (complet) et Nom du fichier contenat les URL des images.
// End Necessary Variables section
/******************************************************************************/
srand((double)microtime()*1000000);
if (file_exists($RANDOM_IMG_FILE)) {
$arry = file($RANDOM_IMG_FILE);
// En: load file.
// Fr: charge le fichier.
for($i = 0; $i < sizeof($arry) ; $i++) {
if (preg_match("/\w+/", $arry[$i]))
$good_arry[$j++] = chop($arry[$i]);
# PHP 4.0 arry_push ($good_arry, $arry[$i]);
}
$randval = rand(0, sizeof($good_arry) -1);
$html_result = "";
} else {
$html_result = "error: can't open $RANDOM_IMG_FILE file";
}
// En: End PHP Code
// Fr: Fin code PHP
?>
[/php]
Everything up to the loop makes sense. And the loop in itself makes sense i'm not sure what the preg_match does. I know it's kind of like substring and looked it up on php.net. From what I gather it searches for any character on a keyboard in the string it reads? and if that's the case, what are the /'s for?
Basically can someone explain how the loop works to me?
0
Comments
Once it gets to the end of the filename it chops off any white space. It then picks a random picture by generating a random number and pulling that picture from the array, then outputs the HTML.