synking Posted February 16, 2011 Share Posted February 16, 2011 I am having trouble trying to fix my eregi call in my script. I have a reporting tool that grabs information from the user agent when they email help questions. I used eregi to find the string in an array and print out when it finds a match. I don't fully understand the PCRE functions so i don' t know if i am using them right. what i have is foreach($OSList as $CurrOS=>$Match) { // Find a match if (eregi($Match, $_SERVER['HTTP_USER_AGENT'])) { // We found the correct match break; } } I know i need to change this around for PCRE preg_match maybe but i am not sure. if anyone could send me a tutorial or help me out it would be great. EDIT: notice the foreach was not correct Quote Link to comment https://forums.phpfreaks.com/topic/227867-eregi-replacement-help/ Share on other sites More sharing options...
ManiacDan Posted February 16, 2011 Share Posted February 16, 2011 Without seeing the contents of $Match, all we can tell you is that you're calling the ereg function properly, but you shouldn't be using it in the first place. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/227867-eregi-replacement-help/#findComment-1175010 Share on other sites More sharing options...
synking Posted February 16, 2011 Author Share Posted February 16, 2011 oh sorry and thanks. I actually just found that the script i am using is here http://pastebin.com/qBW6pyzv I did not build the tool it was made by another person. The $Match is the array $oslist I would like to be able to update this script if anyone can point me in the right direction. Also what it does if i just swap eregi with preg_match is print out the last option in the array. Quote Link to comment https://forums.phpfreaks.com/topic/227867-eregi-replacement-help/#findComment-1175035 Share on other sites More sharing options...
Maq Posted February 16, 2011 Share Posted February 16, 2011 eregi has been deprecated as of 5.3, you should not use this function. If $match is not a regular expression you should not be using any regex function. If you do need a regex function then use preg_match. If you just want to check if $match exists anywhere in the USER_AGENT then use strpos. Quote Link to comment https://forums.phpfreaks.com/topic/227867-eregi-replacement-help/#findComment-1175038 Share on other sites More sharing options...
ManiacDan Posted February 16, 2011 Share Posted February 16, 2011 Yeah...you want: if ( strpos( $_SERVER['HTTP_USER_AGENT'], $Match ) !== false ) -Dan Quote Link to comment https://forums.phpfreaks.com/topic/227867-eregi-replacement-help/#findComment-1175254 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.