定制 lukaswhite/string-utilities 二次开发

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

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

lukaswhite/string-utilities

Composer 安装命令:

composer require lukaswhite/string-utilities

包简介

Some miscellaneous string utilities for PHP

README 文档

README

A few miscellanous PHP string utilities.

Strip Punctuation

As the name suggests, the stripPunctuation() method strips all punctuation from a string.

Strings::stripPunctuation( 
	'This, is a sentence, with - some - punctuation.' 
);
// outputs This is a sentence with  some  punctuation

To avoid the addtional spaces where the dashes have been replaced, see stripMultipleSpaces()

Strip Multiple Spaces

The stripMultipleSpaces() strips multiple spaces:

Strings::stripMultipleSpaces(
	'This is  a string that has  some extra spaces'
);
// outputs This is a string that has some extra spaces

Replace the nth Occurence of a Substring

If you have a string that contains multiple occurences of a given substring, but only want to replace a specific one, use replaceNth().

Strings::replaceNth( '0', '1', '0000000000', 5 );
// Outputs 0000100000

Replace All But First Occurence of a Substring

If you have a string that contains multiple occurences of a given substring, but want to replace all but the first one then use replaceAllButFirstOccurence().

Strings::replaceAllButFirstOccurence( '0', '1', '0000000000' );
// Outputs 0111111111

Random Hex String

The randomHex() method returns a random hexadecimal number, as a string, to the specified length.

Strings::randomHex( 5 );
// Outputs something like de0f42

To force it to be uppercase, pass true as the second argument.

Strings::randomHex( 5, true );
// Outputs something like DE0F42

Starts With

Use startsWith() to determine whether a string starts with a specified substring.

Strings::startsWith( 'This is a test', 'This' )
// true

By default, the method is case sensitive. To make it case-insensitive, pass false as a third argument.

Strings::startsWith( 'This is a test', 'this', false )
// true

Ends With

Use endsWith() to determine whether a string ends with a specified substring.

Strings::startsWith( 'This is a test', 'test' )
// true

By default, the method is case sensitive. To make it case-insensitive, pass false as a third argument.

Strings::startsWith( 'This is a test', 'Test', false )
// true

Generate an Excerpt

To generate an exceprt; as in, trim a string to a specified maximum number of words:

$excerpt = Strings::excerpt( $content, 25 );

By default this appends ... to the end of the string; change this using the optional third argument, for example:

$excerpt = Strings::excerpt( 
	$content, 
	100,
	'<a href="/path/to/page">Read More</a>'
);

Alternatively, if you need to limit the length of the excerpt to a specified number of characters:

$excerpt = Strings::excerptCharacters( $content, 200 );

lukaswhite/string-utilities 适用场景与选型建议

lukaswhite/string-utilities 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 92 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 09 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 lukaswhite/string-utilities 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 lukaswhite/string-utilities 我们能提供哪些服务?
定制开发 / 二次开发

基于 lukaswhite/string-utilities 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-27