End of Line (#888)

End of line changed from `\n` to `PHP_EOL`
This commit is contained in:
Pen-y-Fan
2021-05-02 12:15:44 +01:00
parent 956872050b
commit 81c7c62414
2 changed files with 5 additions and 6 deletions

View File

@@ -27,11 +27,11 @@ Let's write a simple "Hello, $name" CLI program. To try it out, create a file na
{% highlight php %}
<?php
if ($argc !== 2) {
echo "Usage: php hello.php <name>.\n";
echo "Usage: php hello.php <name>" . PHP_EOL;
exit(1);
}
$name = $argv[1];
echo "Hello, $name\n";
echo "Hello, $name" . PHP_EOL;
{% endhighlight %}
PHP sets up two special variables based on the arguments your script is run with. [`$argc`][argc] is an integer

View File

@@ -19,7 +19,7 @@ output.
$raw = '22. 11. 1968';
$start = DateTime::createFromFormat('d. m. Y', $raw);
echo 'Start date: ' . $start->format('Y-m-d') . "\n";
echo 'Start date: ' . $start->format('Y-m-d') . PHP_EOL;
{% endhighlight %}
Calculating with DateTime is possible with the DateInterval class. DateTime has methods like `add()` and `sub()` that
@@ -34,7 +34,7 @@ $end = clone $start;
$end->add(new DateInterval('P1M6D'));
$diff = $end->diff($start);
echo 'Difference: ' . $diff->format('%m month, %d days (total: %a days)') . "\n";
echo 'Difference: ' . $diff->format('%m month, %d days (total: %a days)') . PHP_EOL;
// Difference: 1 month, 6 days (total: 37 days)
{% endhighlight %}
@@ -43,8 +43,7 @@ You can use standard comparisons on DateTime objects:
{% highlight php %}
<?php
if ($start < $end) {
echo "Start is before the end!\n";
}
echo "Start is before the end!" . PHP_EOL;}
{% endhighlight %}
One last example to demonstrate the DatePeriod class. It is used to iterate over recurring events. It can take two