Monday, 15 March 2010

php - Sort array of file lines by alphabetical -


I am reading a text file of email addresses and only outputing to the domain (with the @ symbol). I would like to make this list alphabet and then output to display on screen

My code is so far like this:

  & lt ;? Php $ file_handle = fopen ("file.txt", "R"); While (.fif ($ file_handle)) {$ line = fgets ($ file_handle); $ Parts = explosion ("@", $ line); $ Id = $ parts [count ($ part) - 1]; Echo "@" $ id "& lt; br & gt;"; } Fclose ($ file_handle); ? & Gt;  

How can I bring the list to alphabet?

This should work for you:

(Here I just click on the file Line. Then I go through each line from where I just array the array to the domain $ lines in the end I sort and print the array with it)

  & lt ;? Php $ lines = array_map (function ($ v) {return "@". Explosion ("@", $ V) [1];}, file ("test.txt")); Type ($ lines); External currency ($ lines as lines) $ line echo "
"; ? & Gt;

Example input / output:

  ab@x.com ac@a.de es@b.cu  
< P>
  @ a.de @ b.cu @x.com  

No comments:

Post a Comment