承接 pointybeard/helpers-functions-strings 相关项目开发

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

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

pointybeard/helpers-functions-strings

最新稳定版本:1.1.3

Composer 安装命令:

composer require pointybeard/helpers-functions-strings

包简介

A collection of functions for manipulating strings

README 文档

README

A collection of functions for manipulating strings

Installation

This library is installed via Composer. To install, use composer require pointybeard/helpers-functions-strings or add "pointybeard/helpers-functions-strings": "~1.1.0" to your composer.json file.

And run composer to update your dependencies:

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update

Requirements

There are no particuar requirements for this library other than PHP 7.2 or greater.

To include all the PHP Helpers packages on your project, use composer require pointybeard/helpers or add "pointybeard/helpers": "~1.2.0" to your composer file.

Usage

This library is a collection convenience function for common tasks relating to string manipulation. They are included by the vendor autoloader automatically. The functions have a namespace of pointybeard\Helpers\Functions\Strings

The following functions are provided:

  • utf8_wordwrap
  • utf8_wordwrap_array
  • type_sensitive_strval
  • mb_str_pad
  • replace_placeholders_in_string
  • random_string
  • random_unique_classname
  • encode_ampersands

Example usage:

<?php

declare(strict_types=1);

include __DIR__.'/vendor/autoload.php';

use pointybeard\Helpers\Functions\Strings;

var_dump(Strings\utf8_wordwrap(
    'Some long string that we want to wrap at 20 characeters',
    20,
    PHP_EOL,
    true
));
// string(55) "Some long string
// that we want to wrap
// at 20 characeters"

var_dump(Strings\utf8_wordwrap_array(
    'Some long string that we want to wrap at 20 characeters',
    20,
    PHP_EOL,
    true
));
// array(3) {
//   [0] => string(16) "Some long string"
//   [1] => string(20) "that we want to wrap"
//   [2] => string(17) "at 20 characeters"
// }

var_dump(Strings\type_sensitive_strval(true));
// string(4) "true"
//
var_dump(Strings\type_sensitive_strval([1, 2, 3, 4]));
// string(5) "array"

var_dump(Strings\type_sensitive_strval(new \stdClass()));
// string(6) "object"

var_dump(Strings\mb_str_pad('Apple', 11, 'àèò', STR_PAD_LEFT, 'UTF-8'));
// string(17) "àèòàèòApple"

var_dump(Strings\mb_str_pad('Banana', 11, 'àèò', STR_PAD_RIGHT, 'UTF-8'));
// string(16) "Bananaàèòàè"

var_dump(Strings\mb_str_pad('Pear', 11, 'àèò', STR_PAD_BOTH, 'UTF-8'));
// string(18) "àèòPearàèòà"

var_dump(Strings\replace_placeholders_in_string(
    ['FIRSTNAME', 'LASTNAME', 'EMAILADDRESS'],
    ['Sarah', 'Smith', 'sarah.smith@example.com'],
    'My name is {{FIRSTNAME}} {{LASTNAME}}. Contact me at {{EMAILADDRESS}}.'
));
// string(62) "My name is Sarah Smith. Contact me at sarah.smith@example.com."

var_dump(Strings\replace_placeholders_in_string(
    ['ONE', 'TWO', 'THREE', 'FOUR'],
    ['apple', 'banana', 'orange', 'banana'],
    '[ONE], [TWO], [THREE], [NOPE]',
    true,
    '[',
    ']'
));
// string(23) "apple, banana, orange, "

var_dump(Strings\random_string(15));
// string(15) "cTAPWAi2EOCop2N"

try {
    var_dump(Strings\random_string(8, '@[^-]@i'));
} catch (Error $ex) {
    echo 'Error generating random string. returned: '.$ex->getMessage().PHP_EOL;
}
// Error generating random string. returned: minimal characters generated. filter '@[^-]@i' might be too restrictive

var_dump(Strings\random_unique_classname('test', '\\MyApp'));
// string(36) "testOIXwzi9D6bAbvy5y9QYoayS2kabbBh56"

var_dump(Strings\encode_ampersands("10 &lt; 15 & 5 &gt; 1. &#x1234;"));
// string(35) "10 &lt; 15 &amp; 5 &gt; 1. &#x1234;"

var_dump(Strings\encode_ampersands('Apples & bananàs and pickles &amp; cheese.'));
// string(47) "Apples &amp; bananàs and pickles &amp; cheese."

Support

If you believe you have found a bug, please report it using the GitHub issue tracker, or better yet, fork the library and submit a pull request.

Contributing

We encourage you to contribute to this project. Please check out the Contributing documentation for guidelines about how to get involved.

License

"PHP Helpers: String Functions" is released under the MIT License.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-05-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固