TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-18-2008, 08:56 PM   #1 (permalink)
The Visitor
 
eHobayyeb's Avatar
 
Join Date: May 2008
Posts: 3
Thanks: 4
eHobayyeb is on a distinguished road
Default Remove duplicates from text array?

Hi guys,

How can I remove duplicates from a text (.txt) file that contain list of Arabic words consider that these words in Arabic alphabet not in Latin alphabet but they are in the (UTF-8) Encodeing?

Please help me I am in a project to provide a spell checker for Arabic in the hunspell project. It is under GPL too.

Thanks,
Mohammad Alhobayyeb
eHobayyeb is offline  
Reply With Quote
Old 08-18-2008, 09:08 PM   #2 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
delayedinsanity is on a distinguished road
Default

Duplicate words?

PHP Code:
$arrfile('file.txt');
array_unique($arr); 
Then write it back to the file, or put er where ever suits you (in a database, in your pocket, in your cars cup holder, or in your wifes bra for safekeeping).
-m
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
eHobayyeb (08-19-2008)
Old 08-18-2008, 09:09 PM   #3 (permalink)
The Gregarious
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
delayedinsanity is on a distinguished road
Default

Duplicate words?

PHP Code:
$arrfile('file.txt');
array_unique($arr); 
Then write it back to the file, or put er where ever suits you (in a database, in your pocket, in your cars cup holder, or in your wifes bra for safekeeping).
-m

edit: Btw this method is assuming each word is on its own line. You may have to get a little more complex if they're all on the same line or delimited in a different way.
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
eHobayyeb (08-19-2008)
Old 08-19-2008, 10:29 AM   #4 (permalink)
The Visitor
 
eHobayyeb's Avatar
 
Join Date: May 2008
Posts: 3
Thanks: 4
eHobayyeb is on a distinguished road
Default

Hi,

It is very good, but see what I faced:

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 4097 bytes) in /var/www/test/test.php on line 8

is there any way to check for duplicates from a file or from a MySQL table instead of array?
eHobayyeb is offline  
Reply With Quote
Old 08-20-2008, 06:27 AM   #5 (permalink)
The Visitor
 
eHobayyeb's Avatar
 
Join Date: May 2008
Posts: 3
Thanks: 4
eHobayyeb is on a distinguished road
Default

Up!up!up!up!
eHobayyeb is offline  
Reply With Quote
Old 08-20-2008, 01:41 PM   #6 (permalink)
The Contributor
 
buggabill's Avatar
 
Join Date: Jan 2008
Location: Maine, USA
Posts: 92
Thanks: 2
buggabill is on a distinguished road
Default

In MySQL you could write a query like the following:

sql Code:
SELECT fieldwithdupes, Count(fieldwithdupes) AS NumOccurances
FROM atable
WHERE fieldwithdupes
IN (SELECT fieldwithdupes
    FROM atable AS tmp
    GROUP BY fieldwithdupes
    HAVING COUNT(*)>1)
    GROUP BY fieldwithdupes;

This will get you a list of the `fieldwithdupes` in `atable` and the number of times that they are repeated. You could adapt this query to your needs.
__________________
-- Bill
"Why is it drug addicts and computer aficionados are both called users?" -Clifford Stoll
buggabill is offline  
Reply With Quote
The Following User Says Thank You to buggabill For This Useful Post:
eHobayyeb (08-21-2008)
Old 08-20-2008, 06:43 PM   #7 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 359
Thanks: 3
xenon is on a distinguished road
Default

I think he wants to select only the distinct words. In which case, this query would work perfectly:

Code:
SELECT DISTINCT(word) FROM table_name GROUP BY word
...assuming that you have each word on its own row.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
The Following User Says Thank You to xenon For This Useful Post:
eHobayyeb (08-21-2008)
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:03 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0