Strip End of Line Characters PHP

by 5 replies
8
Hi Guys

I have a php script that takes input from a form and emails the results. Everything works fine, but users often use the [Return] key at the end of lines and I would like to strip those characters from the variable.

What I usually get is something like this (2 paragraphs) ...

The quick brown fox
jumped over the lazy dog
The quick brown fox
jumped over the lazy dog
The quick brown fox
jumped over the lazy dog

The quick brown fox
jumped over the lazy dog
The quick brown fox
jumped over the lazy dog
The quick brown fox
jumped over the lazy dog

But what I want is this (still 2 paragraphs, but with end-of line characters stripped and paragraphs still intact) ...

The quick brown fox jumped over the lazy dog The quick brown fox jumped over the lazy dog The quick brown fox jumped over the lazy dog

The quick brown fox jumped over the lazy dog The quick brown fox jumped over the lazy dog The quick brown fox jumped over the lazy dog

Can anyone help?

Many thanks

Will
#programming #characters #end #line #php #strip
  • Hi Will,

    The trim() function should work for this. Example:



    \t represents a carriage return.

    Hope that helps.

    Craig
    • [1] reply
    • \t is a tab, not carriage return.
  • Will, I've done this before in other programming languages. The outline is:
    1. Search for all pairs of adjacent returns and replace them with an unusual code such as \|\.
    2. Search for all returns and delete thems.
    3. Search for the unique code and replace it with a pair of returns.

    Chris
  • Thanks guys

    Finally managed it!

    Will
    • [1] reply

Next Topics on Trending Feed

  • 8

    Hi Guys I have a php script that takes input from a form and emails the results. Everything works fine, but users often use the [Return] key at the end of lines and I would like to strip those characters from the variable.