28, May 2012

Array question - webmaster forum

 
Webdigity webmaster forums
[ 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
Instabuck - The easy way to sell digital products online

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



« on: Jun 07, 2006, 04: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 or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Jun 07, 2006, 04:48:08 pm »

maybe you should use the words as key items:

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

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #2 on: Jun 07, 2006, 04: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 or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: Jun 07, 2006, 04:51:54 pm »

 http://www.php.net/ksort

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #4 on: Jun 07, 2006, 05:23:17 pm »

Thanks Smiley

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

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: Jun 07, 2006, 09:01:11 pm »


I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #6 on: Jun 07, 2006, 09: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 or twitter

Last blog : Butterfly Marketing 2.0
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=2782
Bookmark this thread : Digg Del.icio.us Dzone more....

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?
May 28, 2012, 12:56:31 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!






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