2

I've found this line in one of the codes coppied from web but have no ide why they use char() function at the end of it. Please let me know why it is used, what it does and what if I don't use it all.

Thanks in advance.

CODE:

$crlf = chr(13) . chr(10);

echo '<html><head><title>Whatever</title></head><body>Hello</body></html>' . $crlf;
BentCoder
  • 11,419
  • 20
  • 88
  • 154

4 Answers4

6

chr(13) is equivalent to "\r" and chr(10) is equivalent to "\n".

So, $crlf = chr(13) . chr(10); is a string containing "\r\n", a CRLF (newline) as the variable name states.

Jacob Krall
  • 27,156
  • 6
  • 63
  • 76
gen_Eric
  • 214,658
  • 40
  • 293
  • 332
2

chr(13) and chr(10) return the ASCII representations of "Carriage return" and "Line feed". These characters can also be written as "\r\n" in PHP. On a Windows system, CR+LF together represent a newline. (See What is the difference between \r and \n?)

Community
  • 1
  • 1
Jacob Krall
  • 27,156
  • 6
  • 63
  • 76
0

The "chr()" function returns a specific ASCII value. See php chr function and ascii chart - Which should help you understand more :)

fantasitcalbeast
  • 5,105
  • 4
  • 36
  • 67
0

The questioner asked

Please let me know why it is used, what it does and what if I don't use it all.

And I don't think anybody answered that yet ...

The programmer is presumably trying to format the HTML code of the page so that is is more readable when displayed through a browser's 'view source' functionality. So the $crlf could be omitted safely, so long as you don't care what the HTML source looks like.

Seems an odd decision to use two function calls rather than typing "\r\n", but who knows, the coder may have had his/her reasons.

fred2
  • 995
  • 1
  • 8
  • 27