Remove case sensitivity from this script?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Remove case sensitivity from this script?

Post by JAB Creations »

This script needs to be made case insensitive. So if someone clicks to get to my site using the string 'Two' it will not currently match.

Code: Select all

<?php 
$lostsouls = array( "one", "two", "three");

list($parameter_string) = array_reverse(explode('?', $_SERVER['HTTP_REFERER'])); 
$parameters = explode('&', $parameter_string); 
foreach($parameters as $parameter) { 
    list($key, $value) = explode('=', $parameter); 
    $args = explode('+',$value); 
    foreach($args as $item){ 
        if(in_array($item,$lostsouls)){header("Location: http://www.example.com/"); 
        } 
    } 
} 
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What have you tried?
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Post by JAB Creations »

Code: Select all

in_array(trim(mb_strtolower($item)),$lostsouls)

Code: Select all

in_array(trim(strtolower($item)),$lostsouls)

Code: Select all

in_array(strtolower($item),$lostsouls)

Code: Select all

(in_array(strtolower($item),strtolower($lostsouls))
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Post by JAB Creations »

This works fine with Lycos but not with Bearshare...

Code: Select all

<?php 
  $lostsouls = array( "one", "two", "three"); 
  list($parameter_string) = array_reverse(explode('?', $_SERVER['HTTP_REFERER'])); 
  $parameters = explode('&', $parameter_string); 
  foreach($parameters as $parameter) { 
      list($key, $value) = explode('=', $parameter); 
      $args = explode('+',$value); 
      foreach($args as $item){ 
          $item = urldecode($item); 
          $i = explode(' ',$item); 
          foreach($i as $x){ 
              if (in_array(trim(strtolower($item)),$lostsouls)) { 
                  header("Location: http://www.example.com/"); 
              } 
          } 
      } 
  }   
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What are the differences between the two?
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Post by JAB Creations »

Thanks for the replies. Got it working and as always here is the final code...

Code: Select all

<?php 
$lostsouls = array( "one", "two", "three");
  list($parameter_string) = array_reverse(explode('?', $_SERVER['HTTP_REFERER']));
  $parameters = explode('&', $parameter_string);
  foreach($parameters as $parameter) {
      list($key, $value) = explode('=', $parameter);
      $args = explode('+',$value);
      foreach($args as $item){
          $item = urldecode($item);
          $i = explode(' ',$item);
          foreach($i as $x){
              if (in_array(trim(strtolower($x)),$lostsouls)) {
                  header("Location: http://www.example.com/");
              }
          }
      }
  }
?>
Post Reply