andytan91 Posted August 18, 2010 Share Posted August 18, 2010 Hello guys i am doing a search function whereby users can check whether a setting is Pass or Fail. After user press the search button, it will return the file which contain the settings the user wants. However i have encountered a problem, currently i am using if statement and && operator to search for file so if the file is missing a string whereby the preg_match function couldn't find it, it will not output the file if i check another setting. Hence i am interested on what other options can i use. Also, Is it possible to use while loop? I tried for awhile and my browser just keeps loading and loading. Thanks for the help! Example: I want to check File 1 for Maximum Password Age settings but it does not contain Service Pack Requirement string... if ((preg_match("/\bService Pack Requirement:(.*)./", $allFiles)) && (preg_match("/\bMaximum Password Age Requirement:(.*)./", $allFiles)) && (preg_match("/\bMinimum Password Length:(.*)./", $allFiles)) && (preg_match("/\bAudit Account Logon Events:(.*)./", $allFiles)) { echo "<a href=\"$file\" target=\"_blank\"> $file </a><br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/211100-outputting-result-correctly/ Share on other sites More sharing options...
TOA Posted August 18, 2010 Share Posted August 18, 2010 I'm trying to figure out what you need. Are you trying to get file permissions? A part of a file? Just to see if a file exists? Can you clarify a little? Quote Link to comment https://forums.phpfreaks.com/topic/211100-outputting-result-correctly/#findComment-1100907 Share on other sites More sharing options...
andytan91 Posted August 19, 2010 Author Share Posted August 19, 2010 Sorry for not being clear..what i want to do is that if that particular string exist in that file, the search function will display the filename. However, as i am using if statement and && operation, i have trouble displaying the filename because if that particular string exist and the others don't, it wont display the file. Ultimately, i want the search function to display the filename if it matches just one preg_match function regardless whether other preg_match function in the if statement can find the other string or not.. Example: User wants to find Service Pack string and Maximum Password Age string which contain "Pass". However, the text file does not contain Audit Account Logon Events" string. Hence, the third preg_match function will not display the file. Sample text Below Service Pack Requirement: Fail Current Settings for Service Pack Requirement: Disabled Maximum Password Age Requirement: Fail Current Settings for Maximum Password Age Requirement: Enabled Minimum Password Length: Pass Current Settings for Minimum Password Length Requirement: Enabled if ((preg_match("/\bService Pack Requirement:(.*)./", $allFiles)) && (preg_match("/\bMaximum Password Age Requirement:(.*)./", $allFiles)) && (preg_match("/\bMinimum Password Length:(.*)./", $allFiles)) && (preg_match("/\bAudit Account Logon Events:(.*)./", $allFiles)) { echo "<a href=\"$file\" target=\"_blank\"> $file </a><br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/211100-outputting-result-correctly/#findComment-1101064 Share on other sites More sharing options...
jcbones Posted August 19, 2010 Share Posted August 19, 2010 Then use the or comparison operator (||). || is equal to OR, it is just higher on the precedence table. Quote Link to comment https://forums.phpfreaks.com/topic/211100-outputting-result-correctly/#findComment-1101066 Share on other sites More sharing options...
andytan91 Posted August 19, 2010 Author Share Posted August 19, 2010 Edit: Hmm i think what you are suggesting might be right...thanks for the help man! I will post again if i encounter any problem! Quote Link to comment https://forums.phpfreaks.com/topic/211100-outputting-result-correctly/#findComment-1101070 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.