Lasso Soft Inc. > Home

[ email_translatebreakstocrlf ]

Method

[Email_TranslateBreakstoCRLF] is a utility method used by the email system to translate any combination of line feed and carriage return characters in a string to carriage return/line feed pairs.

  • Syntax
email_translateBreaksToCRLF('string')
Examples
  • Beginner

Unify all line breaks to the Windows-style carriage return/line feed pairs

The example below counts the number of line breaks in a string with  a mixture of carriage returns and line feeds. We first use the [email_translatebreakstocrlf] method to unify all line breaks to carriage return/line feed pairs. We take the resulting string and split on the carriage return/line feed pairs to get an array whose size tells us the number of lines. We subtract one from that number because the last line won't have a line break, so the result will be the number of line breaks in the string.

Code

email_translatebreakstocrlf('Line Feed\nCarriage Return\rEnd')->split('\r\n')->size - 1

Result

2

Recent Comments

testing 123

Posted on: 14 March 2011

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft