rhyspaterson Posted July 11, 2008 Share Posted July 11, 2008 Hey guys, Have this at the moment: if (preg_match("/a/i", $variable)) { $result++; } If the variable has the letter a in it (not case sensitive), add one to the result. Works fine, however i only want to see if only the second character in the string has the letter a, not go through the whole string. Any suggestions? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/114197-search-string-for-character-at-certain-position/ Share on other sites More sharing options...
rhodesa Posted July 11, 2008 Share Posted July 11, 2008 if (preg_match("/^.a/i", $variable)) { $result++; } Quote Link to comment https://forums.phpfreaks.com/topic/114197-search-string-for-character-at-certain-position/#findComment-587188 Share on other sites More sharing options...
corbin Posted July 11, 2008 Share Posted July 11, 2008 Or, if you feel like not using regexp: if(strlen($str) >= 2 && $str[1] == 'a') Quote Link to comment https://forums.phpfreaks.com/topic/114197-search-string-for-character-at-certain-position/#findComment-587245 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.