zampu Posted July 13, 2007 Share Posted July 13, 2007 Ok i have a text file that looks like this NAME|[email protected]|ipaddress| NAME|[email protected]|ipaddress| NAME|[email protected]|ipaddress| i need to store NAME and their email as 2 separate variables. Please help me! Thanks! Link to comment https://forums.phpfreaks.com/topic/59732-solved-reading-from-a-text-file-and-storing-things-as-variables-pelase-help/ Share on other sites More sharing options...
pocobueno1388 Posted July 13, 2007 Share Posted July 13, 2007 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]; } ?> Link to comment https://forums.phpfreaks.com/topic/59732-solved-reading-from-a-text-file-and-storing-things-as-variables-pelase-help/#findComment-296865 Share on other sites More sharing options...
zampu Posted July 13, 2007 Author Share Posted July 13, 2007 ok but what about for other lines? Link to comment https://forums.phpfreaks.com/topic/59732-solved-reading-from-a-text-file-and-storing-things-as-variables-pelase-help/#findComment-296868 Share on other sites More sharing options...
pocobueno1388 Posted July 13, 2007 Share Posted July 13, 2007 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>'; ?> Link to comment https://forums.phpfreaks.com/topic/59732-solved-reading-from-a-text-file-and-storing-things-as-variables-pelase-help/#findComment-296874 Share on other sites More sharing options...
zampu Posted July 13, 2007 Author Share Posted July 13, 2007 ok but now i gotta send an email to each one. And i have to make it like hello $name etc... So i need to incorperate thier name. Any help? Link to comment https://forums.phpfreaks.com/topic/59732-solved-reading-from-a-text-file-and-storing-things-as-variables-pelase-help/#findComment-296883 Share on other sites More sharing options...
pocobueno1388 Posted July 13, 2007 Share Posted July 13, 2007 <?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. Link to comment https://forums.phpfreaks.com/topic/59732-solved-reading-from-a-text-file-and-storing-things-as-variables-pelase-help/#findComment-296886 Share on other sites More sharing options...
zampu Posted July 13, 2007 Author Share Posted July 13, 2007 Thanks so much, i really appreciate it! Link to comment https://forums.phpfreaks.com/topic/59732-solved-reading-from-a-text-file-and-storing-things-as-variables-pelase-help/#findComment-296888 Share on other sites More sharing options...
pocobueno1388 Posted July 13, 2007 Share Posted July 13, 2007 Don't forget to press "solved". Link to comment https://forums.phpfreaks.com/topic/59732-solved-reading-from-a-text-file-and-storing-things-as-variables-pelase-help/#findComment-296891 Share on other sites More sharing options...
zampu Posted July 13, 2007 Author Share Posted July 13, 2007 Do you have paypal? Link to comment https://forums.phpfreaks.com/topic/59732-solved-reading-from-a-text-file-and-storing-things-as-variables-pelase-help/#findComment-296920 Share on other sites More sharing options...
pocobueno1388 Posted July 13, 2007 Share Posted July 13, 2007 Yes...? You can send me a message if you want instead of talking over this thread. It would probably be appreciated by the other forum helpers. I will send you a message. Link to comment https://forums.phpfreaks.com/topic/59732-solved-reading-from-a-text-file-and-storing-things-as-variables-pelase-help/#findComment-296966 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.