phpnewbieca Posted October 30, 2009 Share Posted October 30, 2009 I have 2 questions: First I need to know how to read a file into an array. Second, I need to know how to search a file for a number (8 digit). Why? Good question, I am storing the content of a form in a text file. The form has an 8 digit confirmation number. If I can search a file for that number I can find the information quickly and write it to an email. Any ideas? function send_order() { $myFile = "something .txt"; $fh = fopen($myFile,"r") or die("can't open <i>$myFile</i>"); if(!$fh) { die("couldn't open file <i>$myFile</i>"); } else { while(!feof($MyFile)) { $lines = file('$myFile'); } [b][u] if( $confirmation_number == $confirmation_number){[/u][/b] global $email, $confirmation_number, $from; $send_to = "$from"; $subject ="Valid - Contact Us"; $email_message = " Contact Information has been validated.\n"; $email_message = " Contact requestor within 48 hours.\n"; $email_message. = " $lines [0]\n"; $email_message. = " $lines [1]\n"; $email_message. = " $lines [2]\n"; $email_message. = " $lines [3]\n"; $email_message. = " $lines [4]\n"; $email_message. = " $lines [5]\n"; // create email headers $headers = 'From: '.$from."\r\n". 'Reply-To: '.$from."\r\n" . 'X-Mailer: PHP/' . phpversion(); $formsent = mail($send_to, $subject, $email_message, $headers); if ($formsent) { echo $formsent; } } } Quote Link to comment https://forums.phpfreaks.com/topic/179658-solved-fopenmyfile-r-read-file-into-an-array-output-array-info-to-email/ Share on other sites More sharing options...
cags Posted October 30, 2009 Share Posted October 30, 2009 You can use the file function to load a file into an array. Then you should be able to use a foreach loop to loop through and compare against the value. You could possibly use array_search for the search, depends what other information is on each line etc. Quote Link to comment https://forums.phpfreaks.com/topic/179658-solved-fopenmyfile-r-read-file-into-an-array-output-array-info-to-email/#findComment-947973 Share on other sites More sharing options...
phpnewbieca Posted October 31, 2009 Author Share Posted October 31, 2009 Thank you! I will try array_search() Quote Link to comment https://forums.phpfreaks.com/topic/179658-solved-fopenmyfile-r-read-file-into-an-array-output-array-info-to-email/#findComment-948401 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.