ok i have a string and i want to split it up if it is over a certain length, this is so i can write it on separate lines.

Im guessing i can use strlen() to find the length of the string but then what would i use to split it up at that point into separate variables to i can write them on separate lines.

cheers

mike

    [man]wordwrap[/man] and [man]explode[/man] could be of help

    or [man]preg_split[/man]

      say i got a variable $text and if its over 12 characters i want to split it into to at the 12 character point.

      i think i would just do strlen() and then if its over 12 i would use
      str_split() to split the string into an array from the 12th character.

      havent tried it yet but that seems logical enough i guess, i probably shoulda worked that out b4 i posted.

        ok i got it working, only now i got another problem, say when it gets to the cut off point it puts the rest on a new line, say the text is only 8 characters and i got a 12 character line, in which case i will want the text in the middle, i will probably have to add space to the start of the string im guessing, im sure i will work it out.

          thanks for that, saved me searching through the functions, this script is getting more complex by the second

            How much scripting have you done before? That is the nature of most scripts -- they tend to get longer and more complicated as you go along. You may want to go back and read through your code to see if there are more efficient ways of doing the things you are doing.

            You should also do more planning. Write "pseudo-code" to describe your application, and once you are sure you have described exactly what you want to do, then go back and replace the pseudo-code with real code.

              Write a Reply...