11-17-2009, 08:17 PM
(11-11-2009, 04:45 PM)Spl3en Wrote: Thanks for this tips, it's really useful for making a code easy to read.
Another manner to do that, a bit more "proper" is to use chr(10) IMHO.
Example :
PHP Code:<?php
$multiline = chr(10);
echo "Hello".$multiline."This is multilines!";
?>
How is this more proper? the chr() function returns the ascii value of a number, so how does calling a function to get the ascii value of 10 (I'm guessing it's the newline char, as that's the only thing that would make sense in this case) a more proper way of implementing a multiline string?
What you did makes use of a needless variable, and it is harder to understand what you were trying to accomplish.
Another possible way of implementing newline's is '\n', which would look something like:
PHP Code:
echo "lol \n new line";
However, \n's aren't really an alternative to heredoc's as they aren't really friendly to your eyes.
Think about it, which one makes more sense?
PHP Code:
$intro = "Hello, sir!\ntoday we will be offering you lots of stuff.\nyou can get a tv\na computer\nor a new desk!\nchoose now.\n";
or...
PHP Code:
$intro = <<<EOL
Hello, sir!
today we will be offering you lots of stuff.
you can get a tv
a computer
or a new desk!
choose now.
EOL;
Sorry, I kinda rambled there. In short, chr() should definitely not be used for implementing newlines within a string ;).
Also, nice guide Master Of The Universe.