I'm trying to split a text string up into paragraphs using explode.

The format of the string means that a new paragraph will always be represented by two newline characters in succession (i.e. \n\n) but when explode'ing using "\n\n" as the separator, it doesn't explode a damn thing.

It seems (as is stated in the manual notes) that explode does not like multiple characters in a separator string.

Is there a way around this?

Thanks in advance.

    Try to replace the \n's on input with a special sign, the ascii-value or just <br><br>, then do an explode on those.

    I've never experienced any problems when exploding with multiple chars, but the \n is a touchy char.

    knutm :-)

      Thanks, I tried that but it still didn't work - even str_replace didn't seem to like taking multiple \n's.

      But then I looked in the HTML source and noted that the lines were still being broken even after I'd replaced the \n's with something else, which meant that I was missing something.

      Then I thought about \r.

      Exploding on \r\n\r\n does the job fine now, so thanks 🙂

        hi the hex values for \n is \x0a and for \r its \x0d

        hope this helps!

          I guess you can explode with '\n' as separator and then apply trim() to every result string, cause trim() should delete all whitespaces which appear at the beginning/end of a string..
          Maybe that helps

            Uh-oh - the hidden carriage return :eek:

            Well, this is a very typical php-problem, where we look for the wrong thing :p

            knutm - prefers simple parse-errors, printed neatly in red :p

              Write a Reply...