Jump to content

[SOLVED] Reading from a text file, and storing things as variables, pelase help.


zampu

Recommended Posts

Give this a try:

 

<?php

$file = file("path/to/file");

foreach ($file as $line){
    $line = trim($line);
    $split = explode("|", $line);
    
    //Variables you want
    $name = $split[0];
    $email = $split[1];
    $ip = $split[2];  
}

?>

If you want you can store everything in an array, so you can access anything you need from whatever line.

 

<?php

$file = file("path/to/file");

foreach ($file as $line){
    $line = trim($line);
    $split = explode("|", $line);
    
    //Variables you want
    $name[] = $split[0];
    $email[] = $split[1];
    $ip[] = $split[2];
    
}

echo '<pre>';
print_r($name);
echo '</pre>';

echo '<pre>';
print_r($email);
echo '</pre>';

echo '<pre>';
print_r($ip);
echo '</pre>';

?>

<?php

$file = file("path/to/file");

foreach ($file as $line){
    $line = trim($line);
    $split = explode("|", $line);
    
    //Variables you want
    $name = $split[0];
    $email = $split[1];
    $ip = $split[2];  
    
    //mail the person
    $to = $email;
    $subject = "Subject Here";
    $body = "Hello $name";
    $from_header="From: [email protected]";
    mail($to,$subject,$body,$from_header);
}

?>

 

That will email each individual person.

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.