473,395 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

hashing and indexing



hello,

i am trying to count all of the words in a string, and am trying to
determine the best data structure for this.

i would like to be able to do something like

$arr_text = explode(" ", $text);

then, i want to count each unique word in $arr_text

i tried using the words as the array offsets, and of course i found
that this is illegal.

is there a php data structure which can accomplish this for me?

something like python's dictionary data structure would be perfect.

thank you so much for reading.

-d

Oct 27 '06 #1
2 1172
Hello --

Fortunately, there is a function that was designed for this purpose:
str_word_count. So you might do something like this:

$text = 'Some string of random words';
$words = str_word_count($text, 1);
$unique_words = array_unique($words);
$number_unique_words = count($unique_words);
print $number_unique_words;

I hope this helps.
Geoffrey
sp********@gmail.com wrote:
hello,

i am trying to count all of the words in a string, and am trying to
determine the best data structure for this.

i would like to be able to do something like

$arr_text = explode(" ", $text);

then, i want to count each unique word in $arr_text

i tried using the words as the array offsets, and of course i found
that this is illegal.

is there a php data structure which can accomplish this for me?

something like python's dictionary data structure would be perfect.

thank you so much for reading.

-d
Oct 27 '06 #2
Following on from 's message. . .

See array_count_values() in the manual. I Believe this is exactly what
you're looking for.
>

hello,

i am trying to count all of the words in a string, and am trying to
determine the best data structure for this.

i would like to be able to do something like

$arr_text = explode(" ", $text);

then, i want to count each unique word in $arr_text

i tried using the words as the array offsets, and of course i found
that this is illegal.

is there a php data structure which can accomplish this for me?

something like python's dictionary data structure would be perfect.

thank you so much for reading.

-d
--
PETER FOX Not the same since the porcelain business went down the pan
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Oct 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Pat | last post by:
I want to look for some one-to-one hashing function. In C++, any one-to-one hashing function?
1
by: snowteo | last post by:
Hi,I have to do this exercises can you help me: 1)Write a program to implement exetendible hashing.If the table is small enough to fin in main memory,how does its performance compare with open and...
11
by: Wm. Scott Miller | last post by:
Hello all! We are building applications here and have hashing algorithms to secure secrets (e.g passwords) by producing one way hashes. Now, I've read alot and I've followed most of the advice...
10
by: Dino M. Buljubasic | last post by:
Hi, I am using MD5 to hash my passwords and add them to database as hashed. I have noticed though that some passwords don't get recognized and I suppose that it happen because hashing might...
3
by: myPosts | last post by:
Hi all, I am having class which is derived from collectionbase class. I am adding some string elements to this collection. What i want is to add support of hashing into class which i have...
19
by: Ole Nielsby | last post by:
How does the GetHashCode() of an array object behave? Does it combine the GetHashCode() of its elements, or does it create a sync block for the object? I want to use readonly arrays as...
8
by: Maya | last post by:
Hello all, I'm using MD5 hashing in my application to give unique values to huge list of items my application receives, originally every item's name was difficult to use as an id for this item...
6
by: Jayender | last post by:
Hi, What is the difference between Hashing and Encryption ?
1
by: Tinku | last post by:
Hi friends I know Static Hashing and i know about Dynamic Hashing, still i have problem to make program with Dynamic Hashing I am new in "C" world, please help me, my problem is: i have to...
15
by: Vinodh | last post by:
I am reading about hashing techniques. The map data structure available in C++ STL uses hashing techniques?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.