karker Posted May 13, 2011 Share Posted May 13, 2011 $ham_dizi = "instein'ın görelilik kuramları ile gerçekleştiğini söylemek yanlış olur. Klasik mekanik çok başarılı olmasına karşın, 1800'lü yılların sonlarına doğru, siyah cisim ışıması, tayf çizgileri, fotoelelektrik etki gibi bir takım olayları açıklama da yetersiz kalmıştır. Açıklamaların yanlışlığı bilim adamlarının yetersizliğinden değil aksine klasik mekaniğin yetersizliğinden kaynaklanıyordu. Klasik mekanikteki sorunun ne olduğunu anlatmak aşırı teknik kaçacaktır"; $ex_dizi = explode(' ',$ham_dizi); $delimiter = count($ex_dizi); for($zi =0; $zi<$delimiter-1; $zi++) { $kactane_Var = substr_count($ham_dizi,$ex_dizi[$zi]); $a3 = $kactane_Var.": [". $zi."] "; echo $a3 ; } Array Repait and Array sort 1: [0] 1: [1] 1: [2] 2: [3] 1: [4] 1: [5] 2: [6] 1: [7] 2: [8] 2: [9] 1: [10] 1: [11] 1: [12] 1: [13] 1: [14] 1: [15] 1: [16] 1: [17] 1: [18] 1: [19] 1: [20] 1: [21] 1: [22] 1: [23] 1: [24] 1: [25] 1: [26] 1: [27] 1: [28] 1: [29] 2: [30] 3: [31] 1: [32] 1: [33] 1: [34] 1: [35] 1: [36] 2: [37] 1: [38] 1: [39] 1: [40] 1: [41] 2: [42] 1: [43] 2: [44] 1: [45] 1: [46] 2: [47] 1: [48] 1: [49] 1: [50] 1: [51] i want to Most ordinary scattered again into an array to assign the first 5 words Quote Link to comment Share on other sites More sharing options...
wigwambam Posted May 13, 2011 Share Posted May 13, 2011 Don't fully understand what you are doing, but can't you sort the array afterwards? Quote Link to comment Share on other sites More sharing options...
karker Posted May 13, 2011 Author Share Posted May 13, 2011 so i want take first most repaited words in the $dynamic array("$dynamic") Quote Link to comment Share on other sites More sharing options...
wigwambam Posted May 13, 2011 Share Posted May 13, 2011 if you google 'sort array php' there are lots of examples. Personally, I would sort the array in descending order of values, then loop 5 times to get the 5 most used. Sorry I can't be of any more help, I need to dash out... Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted May 14, 2011 Share Posted May 14, 2011 This will find all the keywords in a string and count them by top keywords counted and also display in alphabetical order. If you need anything different or added...change it. <?php //string of text $text = "instein'in görelilik kuramlari ile gerçeklestigini söylemek yanlis olur. Klasik mekanik çok basarili olmasina karsin, 1800'lü yillarin sonlarina dogru, siyah cisim isimasi, tayf çizgileri, fotoelelektrik etki gibi bir takim olaylari açiklama da yetersiz kalmistir. Açiklamalarin yanlisligi bilim adamlarinin yetersizliginden degil aksine klasik mekanigin yetersizliginden kaynaklaniyordu. Klasik mekanikteki sorunun ne oldugunu anlatmak asiri teknik kaçacaktir"; //function to remove any numbers function remove_numbers($string) { $numbers = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "0"); $string = str_replace($numbers, " ", $string); return $string; } //this removes all numbers...I found numbers to be a pain $text = remove_numbers($text); //languages support for strtolower $text = mb_strtolower($text, 'UTF-8'); //any text or characters to remove from string $text = str_replace(array("~","“","»","«"."¦","_","|",";","<",">","'\'","+","||",".","-","=","!","@","#","$","%","^","&","?",";",":","\r","\n",",","*",'"',"(",")","{","}","/","//","--","—","•",'“','”',"•","..","...","..."), ' ', $text); //if any unwanted items would like to exclude from the array such as common words $unwanted_items = array ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","an","at","as","the","for","but","you","your","or","of","on","in","he","she","is","en","la","it","no","size","align","td","to","font"); //explode the text into an array by the spaces $text_array = explode(" ",$text); //create a unique list of keywords $unique_list = array_unique($text_array); //setting a minimum and maximum length $min_length = 3; $max_length = 25; //loop through the keywords foreach($unique_list as $keyword_list){ //checks to only show which keywords make it to the final array if(strlen($keyword_list) >= $min_length && strlen($keyword_list) <= $max_length && !is_numeric($keyword_list) && $keyword_list != "" && !in_array(trim($keyword_list), $unwanted_items)) { //trim any whitespace and also rename the variable $keywords = trim($keyword_list); //count how many occurances the keyword has in the string $count = @mb_substr_count($text, $keywords); //make it a new array $counted_keywords[] = "$count|$keywords"; //if want by alphabetical order $keywords_counted[] = "$keywords|$count"; } } //natural order sort the array natsort($counted_keywords); //reverse the array...wtf....no opposite to natsort??? grrr $counted_keywords = array_reverse($counted_keywords); ?> <table border="1"> <tr> <th>Top Count</th> <th>Alphabetical Keyword</th> </tr> <tr> <td> <?php //loop the new array and display foreach($keywords_counted as $by_keyword){ if(strlen($by_keyword) >= $min_length && strlen($by_keyword) <= $max_length && !is_numeric($by_keyword) && $by_keyword != "" && !in_array(trim($by_keyword), $unwanted_items)) { $keywords = trim($by_keyword); $exploded_keywords = explode("|",$keywords); $cnt = $exploded_keywords[1]; $key = $exploded_keywords[0]; if($key != ""){ echo "$key : $cnt<br />"; } } } ?> </td> <td> <?php //sort keywords alphabetical asort($keywords_counted); //loop the keywords foreach($keywords_counted as $by_keyword){ $exploded_keywords = explode("|",$by_keyword); $cntkey = $exploded_keywords[1]; $keycount = $exploded_keywords[0]; if($key != ""){ echo "$keycount : $cntkey<br />"; } } ?> </td> </tr> </table> output would be: Top Count yetersiz : 3 klasik : 3 yetersizliginden : 2 yanlis : 2 mekanik : 2 ile : 2 aiklama : 2 yillarin : 1 yanlisligi : 1 teknik : 1 tayf : 1 takim : 1 sylemek : 1 sorunun : 1 sonlarina : 1 siyah : 1 olur : 1 olmasina : 1 oldugunu : 1 olaylari : 1 mekanikteki : 1 mekanigin : 1 kuramlari : 1 kaynaklaniyordu : 1 karsin : 1 kalmistir : 1 kaacaktir : 1 izgileri : 1 isimasi : 1 instein'in : 1 grelilik : 1 gibi : 1 gereklestigini : 1 fotoelelektrik : 1 etki : 1 dogru : 1 degil : 1 cisim : 1 bir : 1 bilim : 1 basarili : 1 asiri : 1 anlatmak : 1 aksine : 1 aiklamalarin : 1 adamlarinin : 1 Alphabetical Keyword adamlarinin : 1 aiklamalarin : 1 aiklama : 2 aksine : 1 anlatmak : 1 asiri : 1 basarili : 1 bilim : 1 bir : 1 cisim : 1 degil : 1 dogru : 1 etki : 1 fotoelelektrik : 1 gereklestigini : 1 gibi : 1 grelilik : 1 ile : 2 instein'in : 1 isimasi : 1 izgileri : 1 kaacaktir : 1 kalmistir : 1 karsin : 1 kaynaklaniyordu : 1 klasik : 3 kuramlari : 1 mekanigin : 1 mekanikteki : 1 mekanik : 2 olaylari : 1 oldugunu : 1 olmasina : 1 olur : 1 siyah : 1 sonlarina : 1 sorunun : 1 sylemek : 1 takim : 1 tayf : 1 teknik : 1 yanlisligi : 1 yanlis : 2 yetersizliginden : 2 yetersiz : 3 yillarin : 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.