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.

With the optional chunk length argument, this is very practical.
–
eriscoSep 6 '10 at 15:07

@nikic - I see... and by looking for what needs to be done next, that add part2 only or add part2 and part3, it's a proper way of doing so? (yes... it's another question... but it's so related... :) )
–
MEMSep 6 '10 at 15:13

Since your spec limits the number of chunks to three, I find it quite clear to have three separate variables. When you need dynamic length or have many items, arrays often become the clearer solution.
–
eriscoSep 6 '10 at 15:18

@MEM: If you used the array version and both parts to add are the same you could do: $parts = array_pad(str_split($string, 50), 3, 'THE_VALUE_TO_FILL_WITH');
–
NikiCSep 6 '10 at 15:22

Thanks. Why should we consider those instead of substr?
–
MEMSep 6 '10 at 14:34

There is nothing wrong with substr(). The problem is using variables like a1, a2, a3, ...
–
NotinlistSep 6 '10 at 14:38

Thanks again. So, in order to solve that what do you suggest? :) I mean, I'm absolute sure that we will not in a very long future, have more then 3. So it's not unlimited. - I will edit the question for a better understanding. I'm sure your observation it's even more pertinent there.
–
MEMSep 6 '10 at 14:40

So we use an array and that's the solution for not having 1, 2 3 variable names?
–
MEMSep 6 '10 at 15:03

You can generalize your algorithm with arrays. You can define() some constant to 3 and then use that constant. Then you can change it easily to 2 or 4. Every data should be written only once as a rule of thumb.
–
NotinlistSep 6 '10 at 15:13

you definitely are a php guru. I will do as you suggest, once I got the skills for that. I'm not yet capable of "quickly doing a function for accomplish something" for me, each line it's heavy. But I will get better. Nevertheless, thanks a lot for your time. I will mark your answer as useful, since others, better skilled then me, may found it properly accurate. Thanks again for your time.
–
MEMSep 6 '10 at 15:55