Jump to content

I think i'm using the syntax incorrectly


horizontal

Recommended Posts

Hi Everyone!

 

I'm new to this forum and a newbie with PHP - I'm glad I found this site - I hope to learn a lot!  For my first and hopefully one of few questions, lol..

 

I told my boss i'd help him out with making a script to sort a txt file he has with 92 pages of e-mail addresses into something organized.  Before i work out how to check for duplicates, so on and so forth - I'm trying to do the basics.  I realise this is wrong

 

<?php
$emails=fopen('test.txt','r');
$newlist=fopen('test2.txt','a');
while(! feof($emails))
{
        $newline=fgets($emails);

        $newchar=fgetc($newline);


        if ($newchar==" ")
                fseek($newlist,0,seek_end);
        else

                {
                $addy = fnmatch ("*@*.*",$newline);

                fwrite($newlist,$addy);
                }
}
?>

 

 

I'm just trying to get the script to store a line in the variable and then go by character until it hits a space and move down to the next line to write the next e-mail it finds - I think the sequence im searching for is also a bit off.  I understand I will need a loop of some sort so all the char's in the $newline character are viewed, can someone please help me out - I feel i'm so close to doing this!

Link to comment
Share on other sites

if i wanted to get an array of the different emails (assuming that every single email was seperated by a comma) I would do this

 

$content = file_get_contents('email.txt');
$emails = array();
$emails = explode(',', $content);

array_map("trim", $emails);//this just removes trailing or leading whitespace from all the entries

Link to comment
Share on other sites

Well let's take mikesta707's code and just add a bit:

 

 

$content = file_get_contents('email.txt');
$emails = array();
$emails = explode(',', $content);
$emails = preg_replace('/]*>/', '', $emails);  // strip out all the  from the addresses
array_map("trim", $emails);//this just removes trailing or leading whitespace from all the entries

// Didn't you mention a sort?

sort($emails);

foreach ($emails as $value) {
   // write out to your new file
}

 

[/code]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.