Michdd Posted October 15, 2008 Share Posted October 15, 2008 How do I make a php script ignore a case for user input? The thing I'm using allows users to edit the url and I want to make it ignore case, so that Name = name. So either one will give the same result. Link to comment https://forums.phpfreaks.com/topic/128584-ignore-case/ Share on other sites More sharing options...
aeonsky Posted October 15, 2008 Share Posted October 15, 2008 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!";} Link to comment https://forums.phpfreaks.com/topic/128584-ignore-case/#findComment-666380 Share on other sites More sharing options...
Maq Posted October 15, 2008 Share Posted October 15, 2008 if (strtoupper("Name") == "NAME") {echo "It matches!";} Link to comment https://forums.phpfreaks.com/topic/128584-ignore-case/#findComment-666382 Share on other sites More sharing options...
Michdd Posted October 15, 2008 Author Share Posted October 15, 2008 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 More sharing options...
Maq Posted October 15, 2008 Share Posted October 15, 2008 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 More sharing options...
effigy Posted October 15, 2008 Share Posted October 15, 2008 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 More sharing options...
Michdd Posted October 15, 2008 Author Share Posted October 15, 2008 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 More sharing options...
wildteen88 Posted October 15, 2008 Share Posted October 15, 2008 if you're using PHP5 then you could use stripos Link to comment https://forums.phpfreaks.com/topic/128584-ignore-case/#findComment-666396 Share on other sites More sharing options...
Michdd Posted October 15, 2008 Author Share Posted October 15, 2008 if you're using PHP5 then you could use stripos How would I use that? Link to comment https://forums.phpfreaks.com/topic/128584-ignore-case/#findComment-666397 Share on other sites More sharing options...
thebadbad Posted October 15, 2008 Share Posted October 15, 2008 if you're using PHP5 then you could use stripos How would I use that? Just like you use strpos(). But what if one username is part of an other? E.g. "Jon" would seem online when actually "Jonathan" was. Link to comment https://forums.phpfreaks.com/topic/128584-ignore-case/#findComment-666414 Share on other sites More sharing options...
thebadbad Posted October 15, 2008 Share Posted October 15, 2008 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 More sharing options...
thebadbad Posted October 15, 2008 Share Posted October 15, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.