定制 10quality/php-string-juggler 二次开发

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

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

10quality/php-string-juggler

Composer 安装命令:

composer require 10quality/php-string-juggler

包简介

Juggling with strings in PHP.

README 文档

README

Latest Stable Version Total Downloads License

Juggling with strings in PHP.

This is a forked version of Christian Johansson's phpStringJuggler library.

Major changes:

  • PHP 7 support.
  • Composer support.
  • PHPunit.

Install

composer require 10quality/php-string-juggler

Purpose

The idea is the make it easier to process strings in a object-oriented way.

An instantiated class is compatible with a string so you can use all functions for strings on a instantiated class.

Like this:

$string = new StringJuggler\Juggler('DONEC');`
echo strtolower($string);
// Echoes 'donec'

Examples

Sometimes examples is the best way to learn.

1. Create a StringJuggler

// Use statement
use StringJuggler\Juggler;

$string = new Juggler('Donec id elit non mi porta gravida at eget metus.');

2. Juggle before

$before = $string->getBefore(' id');
// $before now equals 'Donec'

3. Juggle after

$after = $string->getAfter('porta ');
// $after now equals 'gravida at eget metus.'

4. Juggle in a conditional statement

if (($after = $string->getAfter('porta ')) == 'gravida at eget metus.') {
	.. do something
} else {
	.. do something else
}

If you need to verify if something was found compare with '' rather than boolean false, like this, or use the isEmpty() and isNotEmpty() methods.

if (($after = $string->getAfter('porta ')) != '') {
	.. do something
} else {
	.. do something else
}
if ($string->getAfter('porta ')->isNotEmpty()) {
	.. do something
} else {
	.. do something else
}

Because the StringJuggler class will always equal true but not always equal an empty string. That behavior is caused by PHP.

5. Juggle a lot

$string = new \StringJuggler\String('Nullam quis risus eget urna mollis ornare vel eu leo. Vestibulum id ligula porta felis euismod semper. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam porta sem malesuada magna mollis euismod. Vestibulum id ligula porta felis euismod semper. Nullam id dolor id nibh ultricies vehicula ut id elit. Donec id elit non mi porta gravida at eget metus. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Curabitur blandit tempus porttitor. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Etiam porta sem malesuada magna mollis euismod. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Donec id elit non mi porta gravida at eget metus. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Maecenas sed diam eget risus varius blandit sit amet non magna. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.');`

if (($text = $string->getAfter('risus')->getBefore('vel eu')->getTrimmed()) == 'eget urna mollis ornare') {
	.. do something
} else {
	.. do something else
}`

All methods

  • after()
  • before()
  • getAfter()
  • getAfterPosition()
  • getBefore()
  • getBeforePosition()
  • getExplode()
  • getIReplace()
  • getPregMatches()
  • getPregReplace()
  • getReplace()
  • getString()
  • getTrimmed()
  • ireplace()
  • isEmpty()
  • isNotEmpty()
  • pregMatch()
  • pregReplace()
  • replace()
  • setString()
  • trim()

License and attribution

The MIT License (MIT)

Copyright (c) 2015 Christian Johansson

10quality/php-string-juggler 适用场景与选型建议

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

它主要适用于以下技术方向: 「php」 「string」 「juggling」 「juggler」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 10quality/php-string-juggler 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-21