lpxxfaintxx Posted April 22, 2006 Share Posted April 22, 2006 Hello,I have a variable that looks like this:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]0lil alx9d1, BagFullOfRic, YOURMOM, fdndfnfd , fdndfnfd , fdndfnfd, fdndfnfd, fdndfnfd, fdndfnfd, sleeperpick10, BagFullOfRice, BagFullOfRice74, iix3JAD0REuU, iix3JAD0REuU, sinwillsin, sportzr4me18, sleeperpick10, BaSkEtBaLLQT8674, xpjisuuus, BagFullOfShyt, %n, %n, BagFullOfRice, Patelk0014, Patelk0014, BagFullOfRice, BagFullOfRice, , Patelk0014, flirtyazngrl09, bigshot9214, bigshot9214, bigshot9214, mnkmnkz16, bleausky22312, , , fashnFrEEk92, BagFullOfRice, BagFullOfRice, , xbsbdfbdbfdbfd, xbsbdfbdbfdbfd, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, , BagFullOfRice, %n, BagFullOfRice, %n, %n, , BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, %n, BagFullOfRice, BagFullOfRice, %n, BagFullOfRice, %n, BagFullOfRice, %n, BagFullOfShyt, BagFullOfShyt, BagFullOfShyt, rubberducky9314, rubberducky9314, rubberducky9314, %n, %n, BagFullOfRice, BagFullOfRice, BagFullOfRice, %n, Patelk0014, rubberducky9314, bigshot9214, bigshot9214, %n, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice[/quote]Is it possible to count how many of the same names are in there?For example: (echoed out text)0lil alx9d1 (1)sleeperpick10 (2)BagFullOfRice (34)%n (27)bigshot9214 (3)Where the number in the parentheses is how many of the same names are in the variable. Regards,AIMMultimedia Quote Link to comment Share on other sites More sharing options...
litebearer Posted April 22, 2006 Share Posted April 22, 2006 Yes, there is....[code]<?PHP$var00 = "0lil alx9d1, BagFullOfRic, YOURMOM, fdndfnfd , fdndfnfd , fdndfnfd, fdndfnfd, fdndfnfd, fdndfnfd, sleeperpick10, BagFullOfRice,BagFullOfRice74, iix3JAD0REuU, iix3JAD0REuU, sinwillsin, sportzr4me18, sleeperpick10, BaSkEtBaLLQT8674, xpjisuuus,BagFullOfShyt, %n, %n, BagFullOfRice, Patelk0014, Patelk0014, BagFullOfRice, BagFullOfRice, , Patelk0014, flirtyazngrl09, bigshot9214, bigshot9214, bigshot9214, mnkmnkz16, bleausky22312, , , fashnFrEEk92, BagFullOfRice, BagFullOfRice, , xbsbdfbdbfdbfd, xbsbdfbdbfdbfd, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, , BagFullOfRice, %n, BagFullOfRice, %n, %n, , BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, %n, BagFullOfRice, BagFullOfRice, %n, BagFullOfRice, %n, BagFullOfRice, %n, BagFullOfShyt, BagFullOfShyt, BagFullOfShyt, rubberducky9314, rubberducky9314, rubberducky9314, %n, %n, BagFullOfRice, BagFullOfRice, BagFullOfRice, %n, Patelk0014, rubberducky9314, bigshot9214, bigshot9214, %n, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice, BagFullOfRice";############ convert the variable to an array$var02 = explode(",",$var00);?><pre><?PHPprint_r(array_count_values($var02));?></pre><?PHP ?>[/code]note that due to spaces in your variable it will appear that some of the elements are duplicated. to resolve this remove all spaces from the variable BEFORE you convert it to an arrayLite... Quote Link to comment Share on other sites More sharing options...
lpxxfaintxx Posted April 22, 2006 Author Share Posted April 22, 2006 Thanks!, but the results is this:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Array( [0lil alx9d1] => 1 [ BagFullOfRic] => 1 [ YOURMOM] => 1 [ fdndfnfd ] => 2 [ fdndfnfd] => 4 [ sleeperpick10] => 2 [ BagFullOfRice] => 42 [BagFullOfRice74] => 1 [ iix3JAD0REuU] => 2 [ sinwillsin] => 1 [ sportzr4me18] => 1 [ BaSkEtBaLLQT8674] => 1 [ xpjisuuus] => 1 [BagFullOfShyt] => 1 [ %n] => 13 [ Patelk0014] => 4 [ ] => 6 [ flirtyazngrl09] => 1 [ bigshot9214] => 5 [ mnkmnkz16] => 1 [ bleausky22312] => 1 [ fashnFrEEk92] => 1 [ xbsbdfbdbfdbfd] => 2 [ BagFullOfShyt] => 3 [ rubberducky9314] => 4).[/quote]Is there any way I can make it more neat, like 0lil alx9d1 (1) <br>BagFullOfRic (1) <br>YOURMOM] (1) <br>fdndfnfd (2) <br>fdndfnfd (4) <br>sleeperpick10 (2) <br> BagFullOfRice] (42) <br>BagFullOfRice74] (1) <br>Or at least:iix3JAD0REuU] => 2 sinwillsin] => 1 sportzr4me18] => 1 BaSkEtBaLLQT8674] => 1 xpjisuuus] => 1 BagFullOfShyt] => 1 Thanks. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 22, 2006 Share Posted April 22, 2006 Surround the print_r() with the '<pre>' & '</pre>' tags:[code]<?php$var02 = explode(",",$var00);echo '<pre>' . print_r(array_count_values($var02),true) . '</pre>';?>[/code]Or you can use a foreach[code]<?php$var02 = explode(",",$var00);foreach ($var02 as $k => $v) $var02[$k] = trim($v);$var04 = array_count_values($var02);foreach ($var04 as $k => $v) echo $k . ' (' . $v . ')<br>';?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
lpxxfaintxx Posted April 22, 2006 Author Share Posted April 22, 2006 Thanks so much, it works perfectly. 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.