Create Carriage Return in PHP String?

2019-01-23 05:16发布

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

6条回答
冷血范
2楼-- · 2019-01-23 05:49

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
查看更多
何必那么认真
3楼-- · 2019-01-23 05:59

I find the adding <br> does what is wanted.

查看更多
迷人小祖宗
4楼-- · 2019-01-23 06:05

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

Stackoverflow reference

查看更多
我只想做你的唯一
5楼-- · 2019-01-23 06:05
$postfields["message"] = "This is a sample ticket opened by the API\rwith a carriage return";
查看更多
疯言疯语
6楼-- · 2019-01-23 06:07

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;
查看更多
孤傲高冷的网名
7楼-- · 2019-01-23 06:11

Fragment PHP (in console Cloud9):

echo "\n";
echo "1: first_srt=1\nsecnd_srt=2\n";
echo "\n";
echo '2: first_srt=1\nsecnd_srt=2\n';
echo "\n";
echo "==============\n";
echo "\n";

resulting output:

  1: first_srt=1
  secnd_srt=2

  2: first_srt=1\nsecnd_srt=2\n
  ==============

Difference between 1 and 2: " versus '

查看更多
登录 后发表回答