5, December 2008

Array question - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Array question
« previous next »
Pages: [1] Print

Author Topic: Array question  (Read 795 times)
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8272
42619 credits
Members referred : 3



« on: Jun 07, 2006, 05:39:42 PM »

I am trying to make some kind of tag system. The job of my code would be to extract the words of a text, substruct the common words (eg. in, the, of, my, I, you, etc) and then count how much times each word is repeated and keep the X of them.

My first idea is to do something like this :

Code:
<?php
function getTags($txt){
 
$badWords = array('in''i''me''you''of' );//...........
 
$txt explode (' 'strtolower $txt ));
 
$tags = array();
 foreach ( 
$txt as $tag )
 {
  if ( !
in_array $tag$badWords ) )
  {
     if ( 
in_array $tag$tags ) )
       
$tags[$tag] += 1;
     else
       
$tags[$tag] = 1;
  }
 }
 return 
$tags;
}
?>

[/php]

The result of this would be an array of this type : tag => times repeated

Then I should somehow short the array. Can you give me some ideas?

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6487
39754 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Jun 07, 2006, 05:48:08 PM »

maybe you should use the words as key items:

Code:
$tags['you']...


Last blog : Just a better Internet portal provided by Google
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8272
42619 credits
Members referred : 3



« Reply #2 on: Jun 07, 2006, 05:49:49 PM »

That's what I've used. But I am not sure how I will sort the array then.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6487
39754 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: Jun 07, 2006, 05:51:54 PM »

 http://www.php.net/ksort


Last blog : Just a better Internet portal provided by Google
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8272
42619 credits
Members referred : 3



« Reply #4 on: Jun 07, 2006, 06:23:17 PM »

Thanks Smiley

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6487
39754 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: Jun 07, 2006, 10:01:11 PM »



Last blog : Just a better Internet portal provided by Google
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8272
42619 credits
Members referred : 3



« Reply #6 on: Jun 07, 2006, 10:03:13 PM »

Finally I decided to make a different algorith, as the previous was very resources consuming.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=2782
Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Array question
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Dec 05, 2008, 07:52:41 PM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 38.003
Total Topics: 7.685
Total Members: 4.472
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: xeroxss

54 Guests, 4 Users online :

11 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.