Forum Moderators: coopster
<?php$a[1] = "<p style='color: rgb(0,200,0)'>text 1</p>";
$a[2] = "<img border='0' title='title' src='http://images.bestbuy.com/BestBuy_US/en_US/images/abn/2007/cam/dept/n_cam_webcam.gif'/>";
$a[3] = "<p style='color: rgb(153,0,0)'>text 2</p>";$b[1] = "<p style='color: rgb(0,0,200)'>text 3</p>";
$b[2] = "<img border='0' title='title' src='http://images.bestbuy.com/BestBuy_US/en_US/images/abn/2007/cam/dept/n_cam_photoprint.gif'/>";
$b[3] = "<p style='color: rgb(150,150,150)'>text 4</p>";$geta = preg_grep('/(?:jpg)¦(?:gif)¦(?:png)/', $a);
$geta2 = preg_grep('/(?:<span)¦(?:<p)/', $a);
$getb = preg_grep('/(?:jpg)¦(?:gif)¦(?:png)/', $b);
$getb2 = preg_grep('/(?:<span)¦(?:<p)/', $b);if(isset($_COOKIE["w"]) && $_COOKIE["w"]=="one"){
$img = $geta[array_rand($geta)];
$txt = $geta2[array_rand($geta2)];
setcookie("w", "two", time()+60*60*24*730);
}
else {
$img = $getb[array_rand($getb)];
$txt = $getb2[array_rand($getb2)];
setcookie("w", "one", time()+60*60*24*730);
}
echo $img;
echo $txt;
?>
echo $img; pulls any images if there are images in the arrays.
echo $txt; pulls any text if there are any text in the arrays. So both pulls two results per page load.
How can I get it to pull only one random result per page load from all the images and all the text in an array instead of two results?
Please let me know, thank you very much for your help.
[edited by: 101Jen at 7:25 pm (utc) on Nov. 19, 2008]
Then
echo $txt;
displays one text, yes?
Are you saying that you don't want both the image and the text, or that you want to combine the two arrays into one array, or...? I apologize, I just am not understanding what you're after.
Alternatively, you could merge the two arrays:
$geta = array_merge($geta,$geta2);
[edited by: 101Jen at 5:58 am (utc) on Nov. 20, 2008]
<?php
$a= "<p style='color: rgb(0,200,0)'>text 1</p>";
$a[2] = "<img border='0' title='title' src='http://images.bestbuy.com/BestBuy_US/en_US/images/abn/2007/cam/dept/n_cam_webcam.gif'/>";
$a[3] = "<p style='color: rgb(153,0,0)'>text 2</p>";$b[1] = "<p style='color: rgb(0,0,200)'>text 3</p>";
$b[2] = "<img border='0' title='title' src='http://images.bestbuy.com/BestBuy_US/en_US/images/abn/2007/cam/dept/n_cam_photoprint.gif'/>";
$b[3] = "<p style='color: rgb(150,150,150)'>text 4</p>";$get1 = preg_grep('/(?:jpg)¦(?:gif)¦(?:png)/', $a);
$get2 = preg_grep('/(?:<span)¦(?:<p)/', $a);
$get3 = preg_grep('/(?:jpg)¦(?:gif)¦(?:png)/', $b);
$get4 = preg_grep('/(?:<span)¦(?:<p)/', $b);$geta = array_merge($get1,$get2);
$getb = array_merge($get3,$get4);if(isset($_COOKIE["w"]) && $_COOKIE["w"]=="one"){
$getresult = array_rand ($geta);
setcookie("w", "two", time()+60*60*24*730);
}
else {
$getresult = array_rand($getb);
setcookie("w", "one", time()+60*60*24*730);
}
echo $getresult;
?>
Also tried this
$geta = array_rand($get1,$get2);
$getb = array_rand($get3,$get4);
if(isset($_COOKIE["w"]) && $_COOKIE["w"]=="one"){
$getresult = $geta;
setcookie("w", "two", time()+60*60*24*730);
}
else {
$getresult = $getb;
setcookie("w", "one", time()+60*60*24*730);
}
echo $getresult;
Then something shows on the page but its numbers of the array and not the content, or the variables $geta or $getb themselves.
[1][edited by: 101Jen at 7:27 pm (utc) on Nov. 20, 2008]
$a[1] = "<p style='color: rgb(0,200,0)'>text 1</p>";
$a[2] = "<img border='0' title='title' src='http://images.bestbuy.com/BestBuy_US/en_US/images/abn/2007/cam/dept/n_cam_webcam.gif'/>";
$a[3] = "<p style='color: rgb(153,0,0)'>text 2</p>";
$b[1] = "<p style='color: rgb(0,0,200)'>text 3</p>";
$b[2] = "<img border='0' title='title' src='http://images.bestbuy.com/BestBuy_US/en_US/images/abn/2007/cam/dept/n_cam_photoprint.gif'/>";
$b[3] = "<p style='color: rgb(150,150,150)'>text 4</p>";
$geta = preg_grep('/(?:jpg)¦(?:gif)¦(?:png)/', $a);
$geta2 = preg_grep('/(?:<span)¦(?:<p)/', $a);
$getb = preg_grep('/(?:jpg)¦(?:gif)¦(?:png)/', $b);
$getb2 = preg_grep('/(?:<span)¦(?:<p)/', $b);
$geta = array_merge($geta,geta2);
$getb = array_merge($getb,getb2);
if(isset($_COOKIE["w"]) && $_COOKIE["w"]=="one"){
$result = $geta[array_rand($geta)];
setcookie("w", "two", time()+60*60*24*730);
}
else {
$result = $getb[array_rand($getb)];
setcookie("w", "one", time()+60*60*24*730);
}
echo $result;
?>
That should work.
<?php
$a[1] = "<p style='color: rgb(0,200,0)'>text 1</p>";
$a[2] = "<img border='0' title='title' src='http://images.bestbuy.com/BestBuy_US/en_US/images/abn/2007/cam/dept/n_cam_webcam.gif'/>";
$a[3] = "<p style='color: rgb(153,0,0)'>text 2</p>";$b[1] = "<p style='color: rgb(0,0,200)'>text 3</p>";
$b[2] = "<img border='0' title='title' src='http://images.bestbuy.com/BestBuy_US/en_US/images/abn/2007/cam/dept/n_cam_photoprint.gif'/>";
$b[3] = "<p style='color: rgb(150,150,150)'>text 4</p>";$get1 = preg_grep('/(?:jpg)¦(?:gif)¦(?:png)/', $a);
$get2 = preg_grep('/(?:<span)¦(?:<p)/', $a);
$get3 = preg_grep('/(?:jpg)¦(?:gif)¦(?:png)/', $b);
$get4 = preg_grep('/(?:<span)¦(?:<p)/', $b);$geta = array_merge($get1,$get2);
$getb = array_merge($get3,$get4);if(isset($_COOKIE["w"]) && $_COOKIE["w"]=="one"){
$result = $geta[array_rand($geta)];
setcookie("w", "two", time()+60*60*24*730);
}
else {
$result = $getb[array_rand($getb)];
setcookie("w", "one", time()+60*60*24*730);
}
echo $result;
?>