Randomise Code
Posted: Tue Jun 10, 2008 1:08 am
Hi,
I had an idea tonight that I might implement on my site, but I don't know how to proceed since I'm a newbie in PHP programming.
I have a web template that has three blocks of information on the right side, and three on the bottom of the page.
The blocks on the right, three of them, looks like this (all in spanish):
Intention for the blocks: To promote services offered
Then the blocks on the bottom looks like this:
Intention for the blocks: Internet Glossary.
What I would like to do is: Write a number of blocks (with the code in it) in a text file to randomly display them as the different pages of the website loads.
I've seen examples of random text, using arrays like this:
I would like to avoid arrays since I think that uploading a text file (built outside the server) would be easier to implement, rather than modifying a php file.
Is this feasible? any ideas or suggestions?
Help would be very much appreciated.
Thanks in Advance.
I had an idea tonight that I might implement on my site, but I don't know how to proceed since I'm a newbie in PHP programming.
I have a web template that has three blocks of information on the right side, and three on the bottom of the page.
The blocks on the right, three of them, looks like this (all in spanish):
Intention for the blocks: To promote services offered
Code: Select all
<div class="right_articles">
<p><img src="images/image1.gif" alt="Image" title="Image" class="image" /><b>Más Valor por su Dinero </b><br />
Consulte la sección de nuestros <a href="paqhosp.php">paquetes de hospedaje</a> para sitios web y correos electrónicos y conozca que podemos hacer por usted o su empresa.</p>
</div>
Intention for the blocks: Internet Glossary.
Code: Select all
<div class="thirds">
<p><b><a href="cms.php" class="title">Gestor de Contenidos</a></b><br />
Los Sistemas de Gestión de Contenidos son generalmente usados para crear, editar, administrar y publicar de manera consistentemente organizada contenido como, noticias, manuales, documentos técnicos y publicidad mediante distintos medios (sigue...) <a href="cms.php"><img src="images/comment.gif" alt="Comment" /></a></p>
</div>
I've seen examples of random text, using arrays like this:
Code: Select all
<?php
$random = array
(
array
(
"image" => "image1.jpg",
"quote" => "quote one",
"link_url" => "http://www.domain.com/?id=1",
"link_text" => "link one"
),
array
(
"image" => "image2.jpg",
"quote" => "quote two",
"link_url" => "http://www.domain.com/?id=2",
"link_text" => "link two"
)
);
$i = mt_rand(0, count($random) - 1);
$size = "";
if(file_exists($random[$i]['image']))
{
$size = " ".array_slice(getimagesize($random[$i]['image']), 3, 1);
}
?>
<table border="0" align="center" cellpadding="0" cellspacing="8">
<tr>
<td><img src="<?php echo $random[$i]['image']; ?>"<?php echo $size; ?> alt="<?php echo $random[$i]['image']; ?>"></td>
</tr>
<tr>
<td><?php echo $random[$i]['quote']; ?></td>
</tr>
<tr>
<td align="center"><a href="<?php echo $random[$i]['link_url']; ?>"><?php echo $random[$i]['link_text']; ?></a></td>
</tr>
</table>
Is this feasible? any ideas or suggestions?
Help would be very much appreciated.
Thanks in Advance.