zongoo
02-10-2005, 02:22 AM
I need a code for removing smaller than 30 chars lines between line breaks in a string. I will pay for a help through cc, stormpay or 2CO.
![]() | View Full Version : Help with some code zongoo 02-10-2005, 02:22 AM I need a code for removing smaller than 30 chars lines between line breaks in a string. I will pay for a help through cc, stormpay or 2CO. Omega-Mark 02-10-2005, 02:25 AM so you want it so there is a minimum of 30 chars in a string before a break right.. this php? zongoo 02-10-2005, 02:35 AM Yes, php. Yes, minimum of 30 chars. Pleaseew pm me if you can help, I'll be back after a few hours. Macord 02-10-2005, 02:44 AM I'm not sure of what you want, but I just typed this small code out of the top of my head based on what you explained: $newString = split("\n", $someString); foreach($newString as $anotherString){ if(!(count($anotherString) < 30)){ $finalString .= $anotherString."\n"; } } basically what it does is splits the string in question by "\n" which is the line break. then each line is treated as an array of strings and counts the characters, if they are not less than 30 it adds it to a new string adding a new line break at the end.. Hope it helps zongoo 02-10-2005, 07:49 AM I see... Resulting is an array, not a string. How to convert it into string? Macord 02-10-2005, 08:17 AM soory zongoo .. I did I mistake yesterday as I did it really quick ... it should be strlen instead of count .. therefore it whould look like $newString = split("\n", $someString); foreach($newString as $anotherString){ if(!(strlen($anotherString) < 30)){ $finalString .= $anotherString."\n"; } } the final string with the lines with more than 30 chars is $finalString Sorry once again for my mistake zongoo 02-10-2005, 08:38 AM No problem, thank you. Now testing it. krumms 02-10-2005, 11:19 AM $s = explode ("\n", $source); $s = array_filter ($s, create_function ('$line', 'return strlen ($line) >= 30;'); $s = join ("\n", $s); or hey, an eye-bleeding one-liner: $s = join ("\n", array_filter (explode ("\n", $source), create_function ('$line', 'return strlen ($line) >= 30;'))); |