承接 exeque/php-dedent 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-11