@@ -321,7 +321,8 @@ Dealing with file paths usually involves some difficulties:
321
321
- Platform differences: file paths look different on different platforms. UNIX
322
322
file paths start with a slash ("/"), while Windows file paths start with a
323
323
system drive ("C:"). UNIX uses forward slashes, while Windows uses backslashes
324
- by default.
324
+ by default. However, Windows also accepts forward slashes, so both types of
325
+ separators generally work.
325
326
- Absolute/relative paths: web applications frequently need to deal with absolute
326
327
and relative paths. Converting one to the other properly is tricky and repetitive.
327
328
@@ -371,28 +372,29 @@ string concatenation for building file paths::
371
372
372
373
echo Path::join('C:\\Program Files', 'PHP', 'php.ini');
373
374
// => C:/Program Files/PHP/php.ini
375
+ // (both forward slashes and backslashes work on Windows)
374
376
375
- The method handles multiple scenarios correctly:
377
+ The `` join() `` method handles multiple scenarios correctly:
376
378
377
- - Empty parts are ignored::
379
+ Empty parts are ignored::
378
380
379
381
echo Path::join('/var/www', '', 'config.ini');
380
382
// => /var/www/config.ini
381
383
382
- - Leading slashes in subsequent arguments are removed::
384
+ Leading slashes in subsequent arguments are removed::
383
385
384
386
echo Path::join('/var/www', '/etc', 'config.ini');
385
387
// => /var/www/etc/config.ini
386
388
387
- - Trailing slashes are preserved only for root paths::
389
+ Trailing slashes are preserved only for root paths::
388
390
389
391
echo Path::join('/var/www', 'vhost/');
390
392
// => /var/www/vhost
391
393
392
394
echo Path::join('/', '');
393
395
// => /
394
396
395
- - Works with any number of arguments::
397
+ Works with any number of arguments::
396
398
397
399
echo Path::join('/var', 'www', 'vhost', 'symfony', 'config', 'config.ini');
398
400
// => /var/www/vhost/symfony/config/config.ini
0 commit comments