SirChick Posted October 28, 2007 Share Posted October 28, 2007 Hey guys, Am needing some help on an idea i brought up... i have scripts and pages that only respond in certain "Cities" on my site... by doing this is put the first letter of each city infront of the script names so there are all like Lhome.php Lgym.php etc Now what i want to try and do is something where by using $_SERVER['PHP_SELF'] I want to use a wild card to do if $_SERVER['PHP_SELF'] begins with L wildcard then ok, else header location "phpscript.php" is this possible, if so how is it done ??? Link to comment https://forums.phpfreaks.com/topic/75106-solved-wildcard-with-php-self/ Share on other sites More sharing options...
trq Posted October 28, 2007 Share Posted October 28, 2007 You could use substr to get the first letter if thats what your after. Link to comment https://forums.phpfreaks.com/topic/75106-solved-wildcard-with-php-self/#findComment-379849 Share on other sites More sharing options...
GingerRobot Posted October 28, 2007 Share Posted October 28, 2007 You don't even need the function: <?php $str = $_SERVER['PHP_SELF']; echo $str[1]; //using 1 rather than 0, since 0 is the forward slash ?> Link to comment https://forums.phpfreaks.com/topic/75106-solved-wildcard-with-php-self/#findComment-379856 Share on other sites More sharing options...
SirChick Posted October 28, 2007 Author Share Posted October 28, 2007 You don't even need the function: <?php $str = $_SERVER['PHP_SELF']; echo $str[1]; //using 1 rather than 0, since 0 is the forward slash ?> I tried this: php script named "London.php" $str = $_SERVER['PHP_SELF']; If ($str{0} == 'L'){ Echo 'test1'; } Else{ Echo ' test2'; } yet it echo's test2 and not test 1 :S Link to comment https://forums.phpfreaks.com/topic/75106-solved-wildcard-with-php-self/#findComment-379878 Share on other sites More sharing options...
trq Posted October 28, 2007 Share Posted October 28, 2007 You don't even need the function: <?php $str = $_SERVER['PHP_SELF']; echo $str[1]; //using 1 rather than 0, since 0 is the forward slash ?> so if it gets that from a php script named "Lcity.php" then $str = L ? No. $str[1] will equal L Link to comment https://forums.phpfreaks.com/topic/75106-solved-wildcard-with-php-self/#findComment-379884 Share on other sites More sharing options...
SirChick Posted October 28, 2007 Author Share Posted October 28, 2007 Oh ok, i changed it to this: If ($str{1} == 'L'){ Echo 'test'; } Else{ Echo 'test2'; } and it echos test 2 even though the php file is London.php Link to comment https://forums.phpfreaks.com/topic/75106-solved-wildcard-with-php-self/#findComment-379886 Share on other sites More sharing options...
GingerRobot Posted October 28, 2007 Share Posted October 28, 2007 Are you sure its London.php with a capital L and not london.php? Link to comment https://forums.phpfreaks.com/topic/75106-solved-wildcard-with-php-self/#findComment-379887 Share on other sites More sharing options...
trq Posted October 28, 2007 Share Posted October 28, 2007 What does... <?php echo $_SERVER['PHP_SELF']; ?> output? Link to comment https://forums.phpfreaks.com/topic/75106-solved-wildcard-with-php-self/#findComment-379889 Share on other sites More sharing options...
Dragen Posted October 28, 2007 Share Posted October 28, 2007 It's probably because it's in a subdirectory, so it's getting the first letter of the folder: /subdirectory/London.php So you need to get only the part after the last / Link to comment https://forums.phpfreaks.com/topic/75106-solved-wildcard-with-php-self/#findComment-379893 Share on other sites More sharing options...
SirChick Posted October 28, 2007 Author Share Posted October 28, 2007 argh its case sensitive damn ! ok its sorted now Link to comment https://forums.phpfreaks.com/topic/75106-solved-wildcard-with-php-self/#findComment-379899 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.