Thanks for reading this... I have a blog type system and when some people cut and paste info into the blog, it appears to have extra carriage returns, and what-not. (See below).

Server: MAILSRV) (Job: daily) daily -- The job failed with the
following error: The directory is invalid.

(Server: MAILSRV) (Job: daily) daily -- The job failed with the
following error: The directory is invalid.

(Server: MAILSRV) (Job: daily) daily -- The job failed with the
following error: The directory is invalid.

I know that trim() can be used to remove leading and trailing carriage returns. But, how do I remove carriage returns in text so that it looks like this....

(Server: MAILSRV) (Job: daily) daily -- The job failed with the
following error: The directory is invalid.
(Server: MAILSRV) (Job: daily) daily -- The job failed with the
following error: The directory is invalid.
(Server: MAILSRV) (Job: daily) daily -- The job failed with the
following error: The directory is invalid.

(Sorry if this is a stupid question, but its late and I've been awake a long time... couldn't solve this by searching google or reading the manual. Thanks)

    Assuming that $text holds the text in question, something like this might work:

    $text = preg_replace('/[\r\n]+/m', "\n", $text);
      laserlight wrote:

      Assuming that $text holds the text in question, something like this might work:

      $text = preg_replace('/[\r\n]+/m', "\n", $text);

      Thank you laser light. One other scenario... sometimes a single carriage return should remain. Is it possible to remove all but one carriage return from a text?

      This is a sample line to demonstrate my question

      This is a sample line to demonstrate my question

      This is a sample line to demonstrate my question

      To look like this....

      This is a sample line to demonstrate my question

      This is a sample line to demonstrate my question

      This is a sample line to demonstrate my question

        What I would probably do is something like the following, in order to ensure the output has valid and semantically meaningful HTML mark-up:

        printf("<p>%s</p>\n", preg_replace('/[\r\n]+/', "</p>\n<p>", htmlentities($text)));
        
          Write a Reply...