baser-b Posted November 14, 2020 Share Posted November 14, 2020 I have this function I use to simplify things. function search_string( $needle, $haystack ) { if ( preg_match_all( "/$needle/im", $haystack ) || strpos( $haystack, $needle ) ) { return TRUE; } return FALSE; } I keep getting this error in my PHP logs, and it comes in a sequence: [07-Nov-2020 05:34:14 America/Los_Angeles] PHP Warning: preg_match_all(): Unknown modifier 'G' in /home/baser-b/public_html/include/functions.php on line 791 [07-Nov-2020 05:34:14 America/Los_Angeles] PHP Warning: preg_match_all(): Unknown modifier 'g' in /home/baser-b/public_html/include/functions.php on line 791 Meaning, it will come with one with the small g, then three with the big G, then one with the small g, then five with the big G, and so on.... My question is, how can I stop getting this error. It won't show me the functions being called to arrive at this answer, as this is likely an error generated by another function calling this one. I was wondering if anyone knew what to change in the search_string function to stop getting this error, why this error is happening, or why the strange repetitive sequence. Is it someone trying to do a hack? The only variable that would be changeable by a visitor would be the $needle variable, so what could they type that has something to do with 'g' to get this? Anyway, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/311704-strange-sequence-in-error-logs-php-warning-preg_match_all-unknown-modifier-g/ Share on other sites More sharing options...
mac_gyver Posted November 14, 2020 Share Posted November 14, 2020 you will get a false return value if an error occurred (you will get a zero return value for no match.) you can specifically detect the false value and log both the $needle value and the debug_backtrace() information. Quote Link to comment https://forums.phpfreaks.com/topic/311704-strange-sequence-in-error-logs-php-warning-preg_match_all-unknown-modifier-g/#findComment-1582355 Share on other sites More sharing options...
jodunno Posted November 14, 2020 Share Posted November 14, 2020 hmm, i think that preg_match_all should have three parameters: preg_match_all ($pattern, $subject, $matches) the posted code only contains $pattern and $subject (2/3). preg_match_all( "/$needle/im", $haystack ) php manual entry for preg match all most helpful text from the php manual: "Searches subject for all matches to the regular expression given in pattern and puts them in matches in the order specified by flags." maybe i am wrong but i think that a proper parameter count will solve the problem. Quote Link to comment https://forums.phpfreaks.com/topic/311704-strange-sequence-in-error-logs-php-warning-preg_match_all-unknown-modifier-g/#findComment-1582356 Share on other sites More sharing options...
kicken Posted November 14, 2020 Share Posted November 14, 2020 9 hours ago, baser-b said: so what could they type that has something to do with 'g' to get this If $needle contains a slash (/) then it will end your regex early and whatever is after it will be the flags. Presumable you're calling the function where $needle contains something like "/G". Do you actually intended for people to enter a regular expression or what? I don't really see the point of this function. Quote Link to comment https://forums.phpfreaks.com/topic/311704-strange-sequence-in-error-logs-php-warning-preg_match_all-unknown-modifier-g/#findComment-1582398 Share on other sites More sharing options...
requinix Posted November 14, 2020 Share Posted November 14, 2020 If the goal is simply to support *s then fnmatch can do that. Quote Link to comment https://forums.phpfreaks.com/topic/311704-strange-sequence-in-error-logs-php-warning-preg_match_all-unknown-modifier-g/#findComment-1582409 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.