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 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++; } 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') 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
Archived
This topic is now archived and is closed to further replies.