Go Back   WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk
Register Blogs FAQ Social Groups CalendarHelp Desk

Reply
 
LinkBack Thread Tools
Old 12-08-2009, 01:43 AM   #1
www.whitedovebooks.co.uk
War Room Member
 
Will Edwards's Avatar
 
Join Date: Jan 2006
Location: United Kingdom.
Posts: 3,829
Blog Entries: 28
Thanks: 367
Thanked 718 Times in 294 Posts
Social Networking View Member's FaceBook Profile  View Member's Twitter Profile  View Member's YouTube Profile
Default Strip End of Line Characters PHP

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

Will Edwards is offline   Reply With Quote
Old 12-08-2009, 02:14 AM   #2
Active Warrior
War Room Member
 
cmaclean's Avatar
 
Join Date: May 2009
Location: Vancouver, British Columbia, Canada
Posts: 95
Thanks: 7
Thanked 8 Times in 7 Posts
Social Networking View Member's FaceBook Profile  View Member's Twitter Profile 
Default Re: Strip End of Line Characters PHP

Hi Will,

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

$text = "The quick brown fox jumped over the";
$emailThisOutput = trim($text, " \t.");


\t represents a carriage return.

Hope that helps.

Craig

cmaclean is offline   Reply With Quote
Old 12-08-2009, 02:34 AM   #3
Enthusiastic Warrior
War Room Member
 
Join Date: Nov 2009
Posts: 815
Blog Entries: 4
Thanks: 222
Thanked 224 Times in 170 Posts
Default Re: Strip End of Line Characters PHP

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
Mr. Enthusiastic is offline   Reply With Quote
Old 12-08-2009, 02:43 AM   #4
HyperActive Warrior
War Room Member
 
Join Date: May 2009
Location: U.K
Posts: 197
Thanks: 5
Thanked 39 Times in 36 Posts
Social Networking View Member's Twitter Profile 
Default Re: Strip End of Line Characters PHP

Quote:
Originally Posted by cmaclean View Post

t represents a carriage return.
\t is a tab, not carriage return.

Best Ways To Make Money Online

Eight bytes walk into a bar. The bartender asks, “Can I get you anything?”
“Yeah,” reply the bytes. “Make us a double.”
Luke Graham is offline   Reply With Quote
Old 12-08-2009, 03:30 AM   #5
www.whitedovebooks.co.uk
War Room Member
 
Will Edwards's Avatar
 
Join Date: Jan 2006
Location: United Kingdom.
Posts: 3,829
Blog Entries: 28
Thanks: 367
Thanked 718 Times in 294 Posts
Social Networking View Member's FaceBook Profile  View Member's Twitter Profile  View Member's YouTube Profile
Default Re: Strip End of Line Characters PHP

Thanks guys

Finally managed it!

Will

Will Edwards is offline   Reply With Quote
Old 12-08-2009, 12:06 PM   #6
Enthusiastic Warrior
War Room Member
 
Join Date: Nov 2009
Posts: 815
Blog Entries: 4
Thanks: 222
Thanked 224 Times in 170 Posts
Default Re: Strip End of Line Characters PHP

Quote:
Originally Posted by Will Edwards View Post
Thanks guys

Finally managed it!

Will
Care to post what you came up with?
Mr. Enthusiastic is offline   Reply With Quote
Reply

  WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk

Tags
characters, end, line, php, strip

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 10:00 PM.