PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 11th, 2006, 06:42 AM
handasse handasse is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 2 handasse User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 4 sec
Reputation Power: 0
Arranging words in alphabetical order

Hi there,
I have a little bit specific problem. I would like to create a script that would read words from a text file and rearange them in alphabetical order. I know it could be easily done using an array but my problem is that I would like to arrange the words form the last letter.
Small example:
the words - a, actual, an, and, brother
would be arranged

a, and, actual, an, brother - because of the alphabetical order - but from the last letter of the word.

There is also one problem - I am from Slovakia and we have little more characters in out alphabet.

Please, if anyone can give me a hand how can I do something like reversing the letter order of the words then delete the words that are repeating, order the words alphabetically and then reverse them again. Thant would do the trick - I just cannot figure out how to do it

thank you.

Matt

Reply With Quote
  #2  
Old April 11th, 2006, 06:57 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 7 h 49 m 32 sec
Reputation Power: 11
Take a look at usort, you can sort with your own caomparator function.

http://php.net/manual/en/function.usort.php

This function would compare the last letter of the words, or whatever else functionality you want, i.e., reverse the words before comparing.

Reply With Quote
  #3  
Old April 11th, 2006, 06:59 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 7 h 49 m 32 sec
Reputation Power: 11
array_unique can remove duplicates from an array by the way. array_map could also be helpfull if you still want to really reverse all elements first..

Reply With Quote
  #4  
Old April 13th, 2006, 01:36 AM
handasse handasse is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 2 handasse User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 4 sec
Reputation Power: 0
First of all I have a problems with getting words into array. I did something like this

$z = file("text_file.txt");
$array_words = array_unique ($z);
$number_words = count ($array_words);
echo "$number_words <BR>";
for ($i=0; $i<=$number_words;$i++) {

echo "' $array_words[$i]' <BR><BR>";
}

But this is reading whole paragraphs.

How can I read from a file that has normal text - not just one word per line?


Quote:
Originally Posted by Icon
Take a look at usort, you can sort with your own caomparator function.

http://php.net/manual/en/function.usort.php

This function would compare the last letter of the words, or whatever else functionality you want, i.e., reverse the words before comparing.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Arranging words in alphabetical order


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap