exeque/php-dedent
最新稳定版本:0.2
Composer 安装命令:
composer require exeque/php-dedent
包简介
String dedent for PHP
README 文档
README
Dedent is a simple PHP library that removes leading whitespace from a string. It is useful for removing indentation from multi-line strings.
Installation
You can install Dedent using Composer:
composer require exeque/php-dedent
Usage
Basic Usage
Dedent can be used through the Dedent class or the dedent function.
use Exeque\Dedent\Dedent; $output = Dedent::dedent($input); // or $output = dedent($input);
use Exeque\Dedent\Dedent; $input = <<<INPUT This is a multi-line string. It has leading whitespace that we want to remove. - This line has extra indentation that we want to keep. INPUT; $output = dedent($input); // $output: // This is a multi-line string. // It has leading whitespace that we want to remove. // - This line has extra indentation that we want to keep.
Tabbed Input
Dedent replaces tabs with spaces by default (1 tab -> 4 spaces). You can change the number of spaces per tab by passing a second argument to the dedent method.
use Exeque\Dedent\Dedent; $input = <<<INPUT \tThis is a multi-line string. \tIt has leading whitespace that we want to remove. \t\t- This line has extra indentation that we want to keep. INPUT; $output = dedent($input); // $output: // This is a multi-line string. // It has leading whitespace that we want to remove. // - This line has extra indentation that we want to keep. // or with custom tab width $output = dedent($input, 2); // $output: // This is a multi-line string. // It has leading whitespace that we want to remove. // - This line has extra indentation that we want to keep.
Testing
You can run the tests using Pest:
composer test
License
Dedent is open-sourced software licensed under the MIT license.
统计信息
- 总下载量: 46
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-11