Jump to content

Ignore case


Michdd

Recommended Posts

I do not know in what context you want to match that, but you can use the function below.

 

 if (strtolower("Name") == "name") {echo "It matches!";}

 

For it to work now the first letter of the actual name must be upper case. Otherwise it doesn't find the name, is there a way that I can make it so that even if the first letter they put in isn't capital, it will still find the name?

Link to comment
https://forums.phpfreaks.com/topic/128584-ignore-case/#findComment-666385
Share on other sites

For it to work now the first letter of the actual name must be upper case. Otherwise it doesn't find the name, is there a way that I can make it so that even if the first letter they put in isn't capital, it will still find the name?

 

I don't understand, can I see your code?

Link to comment
https://forums.phpfreaks.com/topic/128584-ignore-case/#findComment-666388
Share on other sites

For it to work now the first letter of the actual name must be upper case. Otherwise it doesn't find the name, is there a way that I can make it so that even if the first letter they put in isn't capital, it will still find the name?

 

ucfirst(strtolower("Name"));

Link to comment
https://forums.phpfreaks.com/topic/128584-ignore-case/#findComment-666390
Share on other sites

For it to work now the first letter of the actual name must be upper case. Otherwise it doesn't find the name, is there a way that I can make it so that even if the first letter they put in isn't capital, it will still find the name?

 

I don't understand, can I see your code?

 

<?php

$name = $_REQUEST['name'];

$content = file_get_contents('http://toptfg.wise-projects.com/list.txt');

$online = strpos($content, $name);


$im = imagecreate(100, 30);


$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 255, 0);
$textcolor1 = imagecolorallocate($im, 255, 0, 0);



if( $online === false ) {

imagestring($im, 5, 0, 0, 'Offline!', $textcolor1);

} else {

imagestring($im, 5, 0, 0, 'Online!', $textcolor);

}


header('Content-type: image/png');

imagepng($im);
imagedestroy($im);
?>

 

Now on the list that it's using file_get_contents on the names all start with Capitals, then it uses strpos to search that list, and then outputs a Online, or Offline image, depending if they're on that list or not. But if someone enters online.php?name=example and "Example" is online, it still still say it's offline, because it's not capital, I don't want it to do this.

Link to comment
https://forums.phpfreaks.com/topic/128584-ignore-case/#findComment-666391
Share on other sites

Just had a look at the actual list. You should explode() it, and use in_array() to search for the user:

 

<?php
$name = $_REQUEST['name'];

$content = file_get_contents('http://toptfg.wise-projects.com/list.txt');

$names = explode('<BR>', $content);
array_shift($names);
array_pop($names);

$online = in_array($name, $names);
?>

Link to comment
https://forums.phpfreaks.com/topic/128584-ignore-case/#findComment-666422
Share on other sites

Sorry, forgot your initial problem :) This should work:

 

<?php
$name = $_REQUEST['name'];

$content = file_get_contents('http://toptfg.wise-projects.com/list.txt');

$names = explode('<BR>', $content);
array_shift($names);
array_pop($names);

$online = in_array(ucfirst(strtolower($name)), $names);
?>

Link to comment
https://forums.phpfreaks.com/topic/128584-ignore-case/#findComment-666426
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.