[PHP-DB] Im seeking a solution to check for duplicate entries with an other sequence

2010-01-11 Thread omar zorgui
Hello,

I have a question currently i'm programming a function to remove duplicates
from an array of sentences.
The computer must classify sentences with exactly the same words in it, but
with a different sequence as a duplicate.

The array that i use as a feed is as following:
$sentences[] = this is a example sentence;
$sentences[] = a this is example sentence;
$sentences[] = example this is a sentence;
$sentences[] = this is a example sentence for a function;

I want the computer to keep only two records of the sentence array in this
case (0|1|2) and 3

I made the script as following:

function($sentences) {

foreach($sentences as $sentence) {
$words = explode( ,$sentence);
$sentenceArray[] = $words;
}

foreach(sentenceArray as $sentence) {
// Here i want the same words are in other sentences
}

}

My question is how could i check the $sentence array if there are records in
it with exactly the same words
as my feed?


Re: [PHP-DB] help in implementing a progress bar

2010-01-11 Thread Philip Thompson
On Jan 7, 2010, at 2:36 PM, Vinay Kannan wrote:

 Hello,
 
 Theres this project that I am working on, and a specific module does take
 few secs to process, I am thinking it would be cool to be showing a progress
 bar(some kind on a .gif image) while the script runs, does any one have an
 idea how to implement this?
 
 Thanks,
 Vinay K

This isn't really database related, but ok...

?php
// Progress.php
class Progress {
public function start () {
echo file_get_contents ('progress.html');
flush ();
}
public function end ($url) {
$text  = script type=\text/javascript\;
$text .= window.location = '$url';;
$text .= /script;

echo $text;
flush ();
}
}
?

?php
// process.php - process the stuff
$progress = new Progress();
$progress-start();
// ... Do your processing here ...
$progress-end('nextpage.php');
?

In the progress.html file, it would just be an html page that has an animated 
gif (and whatever else you want on it). Hope this helps.

~Philip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Im seeking a solution to check for duplicate entries with an other sequence

2010-01-11 Thread Richard Quadling
2010/1/11 omar zorgui omarzor...@gmail.com:
 $sentences[] = this is a example sentence;
 $sentences[] = a this is example sentence;
 $sentences[] = example this is a sentence;
 $sentences[] = this is a example sentence for a function;


?php
// Define data.
$Sentences = array
(
this is a example sentence,
a this is example sentence,
example this is a sentence,
this is a example sentence for a function,
);

// Record hashes of the sorted words in each sentence.
$Hashes = array();
$Reduced = array_filter
(
$Sentences,
function($Sentence)
use($Hashes)
{
// Explode the sentence into words but forced to lower case.
$Words = explode(' ', strtolower($Sentence));

// Sort the words
sort($Words);

// If the hash of the serialized words array is not already 
known
if (!in_array($Hash = md5(serialize($Words)), $Hashes))
{
// then add it and return true.
$Hashes[] = $Hash;
return True;
}
else
{
// else return false to filter out this sentence.
return False;
}
}
);

// Show the reduced sentences.
print_r($Reduced);
?


outputs ...

Array
(
[0] = this is a example sentence
[3] = this is a example sentence for a function
)



-- 
-
Richard Quadling
Standing on the shoulders of some very clever giants!
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php