Jump to content

switching text


11Tami

Recommended Posts

Hello, I'm trying to switch to different text on every next page load. So the text below, "something" on one page load and "something else" on another page load. But this isn't working. Can someone please help me fix this? Please let me know its appreciated, thank you very much.

 

<?php
$switching = (isset($_COOKIE['toggle3']) and $_COOKIE['toggle3'] == 1) ? 1 : -1; 
setcookie('toggle3', $switching, 0); 
switch($switching) 
{ 
  case 1: 
     echo "Something"; 
     break; 
  case -1: 
     echo "Something else";
$switching *= -1;
} 
?>

Link to comment
https://forums.phpfreaks.com/topic/85281-switching-text/
Share on other sites

Thanks a lot for the help but I think I still need a cookie. Cause it needs to remember what it saw the time before until the next visit, not to forget soon after the browser closes. I just hadn't put the expiration in the first one yet. Unless someone can tell me why I'm wrong. Please keep all the ideas coming, I really need a fix, thank you very much.

Link to comment
https://forums.phpfreaks.com/topic/85281-switching-text/#findComment-435178
Share on other sites

Thanks a lot, I need it so that if it picked from array one randomly the first time, next time it will pick from array two. How do I write that? Please let me know, thank you very much.

 

<?php
ini_set('error_reporting', 8191);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
$one  = Array(); 
$one[1] = "test";
$two  = Array(); 
$two[1] = "test2";
$get = shuffle($one,$two); 
echo $get;
?>

Link to comment
https://forums.phpfreaks.com/topic/85281-switching-text/#findComment-435736
Share on other sites

I'm bringing it back to basics first to get the first part working, then I'll try to get the second working after that so here's what I have.

 

PHP Code:

 

<? php
$one  = Array();
$one[1] = "test1"; 
$one[2] = "test2";
$one[3] = "test3"; 
$one[4] = "test4";
$get = array_rand($one);
echo $get; 
?>

 

Instead of showing "test1" ect. its only showing 1,2,3, or 4. Anyone know why? Thanks a lot.

Link to comment
https://forums.phpfreaks.com/topic/85281-switching-text/#findComment-435971
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.