Hi,
I new to PHP. I've searched all over, but with no luck.
My objective is to build an array of variables that contain HTML links. (One html link per variable). Then I want to output the variables, (containing the links), so that a new random variable loads each time the page loads.
I'm having problems with:
[1] formatting a link so that it can be inside a variable.
[2] including a random variable inside of an HTML link so that the variable concatenates with the rest of the HTML link to form the completed URL.
My code look like this - at the moment :-)
<?php
$var1 = "<a href="http://link1.com">Link 1</a>";
$var2 = "<a href="http://link2.com">Link 2</a>"";
$var3 = "<a href="http://link3.com">Link 3</a>"";
echo ""; $var1; $var2; $var3;
?>
<?php
$the_array = array( "$var1", "$var2", "$var3", "$var3" ); //<--Note the extra "item3"
shuffle($the_array); // Shuffles the array
echo $the_array[0]; // Becomes the new shuffled array
$random_number = rand(0,($array_count-1)); // Outputs a random variable from the shuffled array.
$random = "$the_array[0]";
?>
I am trying to output the above as follows:
<ul>
<li><?php echo '<a href="http://Link1.com">Link 1</a>.'; ?></li>
<li><?php echo '<a href="http://Link2.com">Link 2</a>.'; ?></li>
<li><?php echo '<a href="http://Link3.com">Link 3</a>.'; ?></li>
</ul>
I've also tried to concatenate the output something like this:
<ul>
<li><?php echo '<a href="http://.$varA.Link1.com">Link 1</a>.'; ?></li>
<li><?php echo '<a href="http://.$varB.Link2.com">Link 2</a>.'; ?></li>
<li><?php echo '<a href="http://.$varC.Link3.com">Link 3</a>.'; ?></li>
</ul>
The idea of the concatenation is to get around having to store the whole 'http://...etc' in the original variables. None of the above worked for me.
I appreciate the help.