thomas-squall/string-utils 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

thomas-squall/string-utils

Composer 安装命令:

composer require thomas-squall/string-utils

包简介

Utilities for string management

README 文档

README

List of available functions

  1. string_starts_with
  2. string_ends_with
  3. string_between
  4. strings_between
  5. string_contains

string_starts_with

Description

Returns true if the $haystack string starts with the $needle string.

Definition

string_starts_with($haystack, $needle)

Where:

  1. $haystack is the string to look into
  2. $needle is the string to check if the $haystack starts with

Usage

$string = "Hello World";

echo "Starts with Hello? " . string_starts_with($string, "Hello");
echo PHP_EOL;
echo "Starts with World? " . string_starts_with($string, "World");

This will print:

Starts with Hello? true
Starts with World? false

string_ends_with

Description

Returns true if the $haystack string ends with the $needle string.

Definition

string_ends_with($haystack, $needle)

Where:

  1. $haystack is the string to look into
  2. $needle is the string to check if the $haystack starts with

Usage

$string = "Hello World";

echo "Ends with Hello? " . string_ends_with($string, "Hello");
echo PHP_EOL;
echo "Ends with World? " . string_ends_with($string, "World");

This will print:

Ends with Hello? false
Ends with World? true

string_between

Description

Returns the first occurrence of the string between the $start and $end string from $string. False if nothing is found.

Definition

string_between($string, $start, $end, $empty_string = false)

Where:

  1. $string is the string to look into
  2. $start is the left string to search
  3. $end is the right string to search
  4. $empty_string determines whether return empty strings or not

Usage

$string_1 = "|Hello|World|";
$string_2 = "||";

echo "String 1: " . string_between($string_1, "|", "|");
echo PHP_EOL;
echo "String 2 with $empty_string false: " . string_between($string_2, "|", "|");
echo PHP_EOL;
echo "String 2 with $empty_string true: " . string_between($string_2, "|", "|", true);

This will print:

String 1: Hello
String 2: false
String 2: 

strings_between

Description

Returns the strings between the $start and $end string from $string. Empty array if nothing is found.

Definition

strings_between($string, $start, $end, $empty_strings = false)

Where:

  1. $string is the string to look into
  2. $start is the left string to search
  3. $end is the right string to search
  4. $empty_strings determines whether return empty strings or not

Usage

$string = "|Hello|World||";

echo "With $empty_strings false:" . PHP_EOL;
print_r(strings_between($string, "|", "|"));
echo PHP_EOL;
echo "With $empty_strings true:" . PHP_EOL;
print_r(strings_between($string, "|", "|", true));

This will print:

With $empty_strings false:
Array ( [0] => Hello [1] => World )

With $empty_strings true:
Array ( [0] => Hello [1] => World [2] => )

string_contains

Description

True or false whether the string $needle is contained in the string $haystack or not.

Definition

string_contains($haystack, $needle)

Where:

  1. $haystack is the string to look into
  2. $needle is the string to check if the $haystack contains

Usage

$string = "Hello";

echo "Contains Hello? " . string_contains($string, "Hello");
echo PHP_EOL;
echo "Contains World? " . string_contains($string, "World");

This will print:

Contains Hello? true
Contains World? false

More utilities coming

thomas-squall/string-utils 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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