Split long string into little ones. - trying to find an elegant way for doing so

Slovaak

New Member
If the string is bigger then 50 chars long, I need to split it.The maximum allowed is 3 chunks of 50. It could be less then 50 but never more then 150.I don't need any special chars to be added, or to serve as "splitters"; I can break the string anywhere, no problem, since the propose is not for showing it to the user. \[code\]if (strlen($street) > 50){ $streetPart1 = substr($street,0,50); $streetPart2 = substr($street,51,100); $streetPart3 = substr($street,101,150);}\[/code\]Is there a more elegant way for doing this?UPDATE:An example of what would arrive next:\[code\]if (strlen($street) > 50){ $streetPart1 = substr($street,0,50); $streetPart2 = substr($street,51,100); $streetPart3 = substr($street,101,150); if(!empty($streetPart2) && empty($streetPart3) { //add part2 only. }elseif(!empty($streetPart2 && !empty($streetPart3)) { //add part 2 and part 3 }}\[/code\]Thanks a lot.MEM
 
Back
Top