Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Carriage Return in PHP String?

We have written a small PHP Hook for our billing system that opens a new support ticket with us when an order is placed. It works except that for the "Open Ticket" API function, it takes a string for the message, but we cannot figure out how to put carriage returns in it.

I have tried

<p>, <br>, \n, \r\n, etc.

As it appears to just be completely plain text though, all of these are just being read verbatim rather than made into carriage returns.

Does anyone have any thoughts on how this could be done? http://docs.whmcs.com/API:Open_Ticket

like image 236
Brett Powell Avatar asked Feb 28 '13 09:02

Brett Powell


People also ask

How do I insert a Carriage Return in a string?

In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF. Adding a new line in Java is as simple as including “\n” , “\r”, or “\r\n” at the end of our string.

How do I add a new line to a string in PHP?

The nl2br() function inserts HTML line breaks (<br> or <br />) in front of each newline (\n) in a string.

Can we use \n in PHP?

?> Using new line tags: Newline characters \n or \r\n can be used to create a new line inside the source code.


3 Answers

Carriage return is "\r". Mind the double quotes!

I think you want "\r\n" btw to put a line break in your text so it will be rendered correctly in different operating systems.

  • Mac: \r
  • Linux/Unix: \n
  • Windows: \r\n
like image 127
Bram Gerritsen Avatar answered Oct 20 '22 23:10

Bram Gerritsen


There is also the PHP 5.0.2 PHP_EOL constant that is cross-platform !

Stackoverflow reference

like image 40
François Breton Avatar answered Oct 21 '22 00:10

François Breton


PHP_EOL returns a string corresponding to the line break on the platform(LF, \n ou #10 sur Unix, CRLF, \n\r ou #13#10 sur Windows).

echo "Hello World".PHP_EOL;
like image 9
Themer Avatar answered Oct 20 '22 23:10

Themer