MarianneB Posted October 8, 2015 Share Posted October 8, 2015 My form's "Textarea" receives this data (exactly like this, scanned straight from the childrens toys ): dog,white cat,white cat,black cat,white dog,black bird,white After clicking "submit," the desired result is a tidy list that has to look just like this: bird: 1 white cat: 2 white, 1 black dog: 1 white, 1 black Well, I've ruined all last weekend, all of monday, all of tuesday, and most of today trying to figure this out. The tricky parts for me is getting php to "keep count" like the cats (2 white, and 1 black). So therefore I humbly come to you all and ask for the code, which is probably a super-simple one-liner that will make me feel foolish Please help? Link to comment Share on other sites More sharing options...
requinix Posted October 8, 2015 Share Posted October 8, 2015 It's not a super-simple one-liner. You say you have code that isn't working? What is it? Link to comment Share on other sites More sharing options...
requinix Posted October 8, 2015 Share Posted October 8, 2015 By the way, the one-liner: $input = "dog,white cat,white cat,black cat,white dog,black bird,white"; $output = current(array_map(function($i){return ksort($i)&&array_walk($i,function(&$v){$v=implode(": ",array_reverse(func_get_args()));})?implode("\n",$i):array();},array(array_map(function($i){return arsort($i)&&array_walk($i,function(&$v){$v=implode(" ",func_get_args());})?implode(", ",$i):array();},array_reduce(preg_split('/\r\n?|\n/',$input),function($c,$i){return@++$c[strtok($i,",")][strtok("")]?$c:$c;},array()))))); echo $output;Obfuscated a bit so it's longer than it needs to be. 2 Link to comment Share on other sites More sharing options...
scootstah Posted October 8, 2015 Share Posted October 8, 2015 I don't think that still counts as a one-liner, lol. Link to comment Share on other sites More sharing options...
requinix Posted October 8, 2015 Share Posted October 8, 2015 Word wrap isn't against the rules. You just need a really wide monitor and a really high resolution. Link to comment Share on other sites More sharing options...
benanamen Posted October 8, 2015 Share Posted October 8, 2015 If you want the best answer for your situation, post your code and form. Link to comment Share on other sites More sharing options...
MarianneB Posted October 8, 2015 Author Share Posted October 8, 2015 I'm always so nervous asking for help because you all will yell at newbies for "asking for FREE help." And usually the answers suck, because you'll say something like "go to www.php.net/complicated_arrays" and tell me to "study up." Therefore, how about this -- if someone wants to Private Message me, I will offer a one-time PayPal amount (if both you and I agree on) to just ONE person who will write the lines of code I want. Link to comment Share on other sites More sharing options...
Jacques1 Posted October 8, 2015 Share Posted October 8, 2015 This isn't Rent-a-Coder. Multiple users have offerered to go through your current code and help you fix the problems. Appearently you don't want that (or maybe there never was any code in the first place). You want somebody to write a “super-simple one-liner” for you while you sit back and relax. It doesn't work like this. Link to comment Share on other sites More sharing options...
benanamen Posted October 8, 2015 Share Posted October 8, 2015 You are not able to get private messages on this site yet. If you want help, all you have to do is provide what was asked for. Your code and your form and preferably an SQL dump of your database. Link to comment Share on other sites More sharing options...
MarianneB Posted October 8, 2015 Author Share Posted October 8, 2015 Jacques1, go to hell. I'm trying to be nice, and all you can come up with is some smart-ass answer. I'm TRYING to get help while avoiding ASSHOLES like yourself.Jackass! Link to comment Share on other sites More sharing options...
scootstah Posted October 8, 2015 Share Posted October 8, 2015 you all will yell at newbies for "asking for FREE help." That's exactly what this is - free help. We volunteer our free time to help people. The least you could do is show some appreciation. Also, nobody is yelling, except for you. And usually the answers suck, because you'll say something like "go to www.php.net/complicated_arrays" and tell me to "study up." Yeah, that's how programming works. You have to be willing to look at a technical document and learn the material. You can't just write what people tell you to write - that's not how it works. By directing you to the manual, we are giving you the materials and resources to actually learn how certain things work, and become a better developer. The point of this forum is to help people through problems with their code. The key phrase here is "their code". You didn't post any code. You said you spent 3 days working on it, so, what do you have to show us? Where are you stuck specifically? This forum is not, "hey I have this problem, can somebody write the solution for me?" If that's what you want, post in the Job Offerings section and pay for the work. But don't come here demanding free answers and then berate the people that give you the answer you don't want to hear. 2 Link to comment Share on other sites More sharing options...
Barand Posted October 8, 2015 Share Posted October 8, 2015 can PHP count white and black cats? I wonder if there's a Facebook API for that. Link to comment Share on other sites More sharing options...
Barand Posted October 8, 2015 Share Posted October 8, 2015 A somewhat simpler one-liner $input = "dog,white cat,white cat,black cat,white dog,black bird,white"; echo '<pre>',print_r(array_count_values(explode("\n", $input)), true),'</pre>'; Link to comment Share on other sites More sharing options...
benanamen Posted October 8, 2015 Share Posted October 8, 2015 Ok, heres the real deal that I got from another forum site. She is using a handheld scanner to scan barcodes on books and putting all the scan data into one text box. No details on the scanner. Pretty sure their is a better option for the scanner output then dumping it all to one textarea. Link to comment Share on other sites More sharing options...
MarianneB Posted October 9, 2015 Author Share Posted October 9, 2015 PLEASE BAN ME AND DELETE ALL THESE POSTS i FEEL LIKE i HAVE WALKED INTO A ROOM OF HALF-ASLEEP ZOMBIES AND NONE OF YOU EVEN READ MY POST, LIKE THE IDIOT BARAND TELLING ME HOW TO "<PRE>" THE TEXTAREA INPUT LIKE THAT ISN'T EVEN WHAT I WANTED. JACKQES MY GOD YOU TAKE THE CAKE AS FAR AS RUDEST ON THE PLANET. Link to comment Share on other sites More sharing options...
MarianneB Posted October 9, 2015 Author Share Posted October 9, 2015 "The least you could do is show some appreciation." FOR WHAT!?! BEING TREATED RUDELY BY A BUNCH OF ZOMBIES? GO BACK TO THE ALT.PERL FORUM FROM WHERE YOU ALL CAME. Link to comment Share on other sites More sharing options...
scootstah Posted October 9, 2015 Share Posted October 9, 2015 You are the only person in this thread that has been rude. The rest have given helpful advice and suggestions, and even wrote code samples doing what you asked for - even though you provided nothing on your end. If you would like help in the future I recommend you actually put forth some effort on your part - instead of throwing a temper-tantrum when you aren't spoonfed the solution to your problems. 1 Link to comment Share on other sites More sharing options...
Recommended Posts