PHP code example of tourze / text-manage-bundle

1. Go to this page and download the library: Download tourze/text-manage-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tourze / text-manage-bundle example snippets


return [
    // ...
    Tourze\TextManageBundle\TextManageBundle::class => ['all' => true],
];

use Tourze\TextManageBundle\Service\TextFormatter;

class MyService
{
    public function __construct(
        private readonly TextFormatter $textFormatter
    ) {
    }
    
    public function process(): string
    {
        // 基本文本处理
        return $this->textFormatter->formatText('Hello World');
    }
}

// 传入参数解析 Twig 语法
$params = ['name' => 'John'];
$text = 'Hello {{ name }}!';
$result = $textFormatter->formatText($text, $params); // 返回 "Hello John!"

// 复杂 Twig 语法
$params = ['items' => ['apple', 'banana', 'orange']];
$text = '{% for item in items %}{{ item }}{% if not loop.last %}, {% endif %}{% endfor %}';
$result = $textFormatter->formatText($text, $params); // 返回 "apple, banana, orange"

// Markdown 格式化
$text = '# Title\n\n**Bold text**';
$result = $textFormatter->formatText($text); // 返回纯文本,移除 HTML 标签