Jump to content

[SOLVED] fopen(MyFile, "r") read file into an array output array info to email


phpnewbieca

Recommended Posts

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;
   }
   }
  }

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.