承接 awssat/str-helper 相关项目开发

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

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

awssat/str-helper

Composer 安装命令:

composer require awssat/str-helper

包简介

A flexible & powerful string manipulation helper for PHP

README 文档

README

Latest Version on Packagist StyleCI Build Status

⚡️ A flexible, simple & yet powerful string manipulation helper for PHP. It gives you the magic of method chaining and it's easier and shorter to be included in views. It Supports most of PHP built-in strings functions (and other useful methods like: contains, equal, append, prepend ...).

str('Hi World')->replace(' ', '+')->lower();

Why use this instead of other string maniplulation packages ?

This is a wrapper for PHP default string functions, to provide a very poweful method chaining and conditions. You don't have to learn new methods names, just use PHP functions names that you know.

Install/Use

You can install the package via composer locally in your project folder:

$ composer require awssat/str-helper

After installing it, just start using StrHelper class, or simply the helper function str():

Examples

str('Hi Hello')->strReplace(' ', '-');
>> hi-hello
str('Hi Hello')->prepend('[')->append(']');
>> [Hi Hello]

In case you want an explicit string value for conditions, use "get":

if(str('Hi')->lower->get() == 'hi') {
        echo 'yes'; 
}
>> yes

There is a "tap" method:

str('LINK.COM')->tap(function($v){ print($v); })->lower();
>> LINK.COM

for callbacks use "do" method:

str('<a>link.com</a>')->do(function($string){ 
        return strip_tags($string); 
});
>> link.com

or:

str('<a>link.com</a>')->do(function(){   
        $this->stripTags();
});
>> link.com

you may notice using camelCase instead of snake_case for method name works too.

You can also use conditions, if(..), else(), endif()

str('<html>hi</html>')
            ->ifContains('hi')
            ->upper();
>> <HTML>HI</HTML>       

if can take an anonymous function

str('<html>hi</html>')
            ->if(function(){
                    return $this->contains('hi');
            })
            ->upper();
>> <HTML>HI</HTML>       

All methods are availabe to be called statically, as:

StrHelper::capitalize('life');

or using str() function.

str()::capitalize('nomad');

[UTF-8 Support] If mbstring library is installed and you call a strpos function, mb_strpos will be called instead.

Tests

Simply use:

$ composer test

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

  • Stars: 44
  • Watchers: 1
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-11-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固