定制 vairogs/functions-text 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

vairogs/functions-text

Composer 安装命令:

composer require vairogs/functions-text

包简介

A PHP library providing enhanced text manipulation functions for string operations, formatting, and transformations

README 文档

README

A PHP library providing enhanced text manipulation functions for string operations, formatting, and transformations.

Installation

Install the package via Composer:

composer require vairogs/functions-text

Requirements

PHP 8.4 or higher

Usage

There are two ways to use this package: via the Functions class or by directly using the traits.

Using the Functions Class

The Functions class provides a wide range of text manipulation functions.

use Vairogs\Functions\Text\Functions;

// Create a new Functions instance
$text = new Functions();

// Convert text to camelCase
$camelCased = $text->camelCase('hello_world'); // Returns "helloWorld"

// Generate a random string
$randomString = $text->randomString(16); // Returns a 16-character random string

// Sanitize text for safe display
$sanitized = $text->sanitize('<script>alert("XSS")</script>'); // Removes HTML tags

// Convert between Cyrillic and Latin
$latin = $text->cyrillicToLatin('Привет мир'); // Converts Cyrillic to Latin
$cyrillic = $text->latinToCyrillic('Privet mir'); // Converts Latin to Cyrillic

// Check if a string starts with any of the given substrings
$startsWithAny = $text->strStartsWithAny('Hello world', ['Hello', 'Hi']); // Returns true

// Limit text by characters or words
$limited = $text->limitChars('This is a long text', 10); // Returns "This is a..."
$limitedWords = $text->limitWords('This is a long text', 2); // Returns "This is..."

Using Traits Directly

Alternatively, you can use the traits directly in your own classes:

use Vairogs\Functions\Text\Traits\_CamelCase;
use Vairogs\Functions\Text\Traits\_RandomString;
use Vairogs\Functions\Text\Traits\_Sanitize;

class MyClass
{
    // Import the traits you need
    use _CamelCase;
    use _RandomString;
    use _Sanitize;

    public function doSomething(): void
    {
        // Use the methods directly
        $camelCased = $this->camelCase('hello_world');
        $randomString = $this->randomString(16);
        $sanitized = $this->sanitize('<script>alert("XSS")</script>');
    }
}

Note that some traits may depend on other helper traits. The Functions class handles these dependencies for you, but if you use the traits directly, you may need to include these helper traits as well.

Features

For a complete list of all functions available in this package, see Features.

License

This package is licensed under the BSD-3-Clause License.

About Vairogs

This package is part of the vairogs/vairogs project - a comprehensive PHP library and Symfony bundle that provides a collection of utilities, components, and integrations for Symfony applications.

The main project includes:

  • Various utility functions and components
  • Doctrine ORM tools and extensions
  • API Platform integrations
  • Symfony bundle for easy configuration
  • And much more

If you find this Text component useful, you might want to check out the full Vairogs project for additional tools and utilities that can enhance your Symfony application development.

To install the complete package:

composer require vairogs/vairogs

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 9
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2025-04-15