josalba/stringplus-php

此包最新版本(0.0.2)没有可用的许可证信息。

0.0.2 2023-03-29 09:34 UTC

This package is not auto-updated.

Last update: 2024-09-25 16:14:53 UTC


README

Minimum PHP Version download

composer require josalba/stringplus-php

此类提供了一系列方法,以简化字符串转换。

方法

  • __toString: 返回结果字符串。
  • in: 检查是否存在于发送作为参数的字符串中。
  • getLength: 字符串长度。
  • equals: 与另一个字符串比较。
  • toMd5: 编码为md5。
  • or: 如果字符串为空,则替换为另一个可选字符串。
  • concat: 如果字符串不为空,则连接字符串。
  • trim
  • removeSpaces: 删除空格。
  • addFirstWith: 在字符串开头连接另一个字符串。
  • addLastWith: 在字符串末尾连接另一个字符串。
  • removeTags: 删除标签。
  • repalce: 在结果中替换一个文本字符串。
  • remplaceWithCallback: 通过回调替换结果中的文本字符串。
  • inArray: 检查此字符串是否存在于数组中。
  • isKeyInArray: 检查此字符串是否为数组中的键。
  • isEmpty: 检查是否为空。

示例

 $text = StringPlus::create('Lorem Ipsum');

结果

 'Lorem Ipsum'

通过创建

 $text = StringPlus::ors('',null,'Lorem Ipsum','','is');

结果

 'Lorem Ipsum'

通过方法

 $text = StringPlus::create('')
    ->or(null)
    ->or('Lorem Ipsum')
    ->or('')
    ->or('is');

结果

 'Lorem Ipsum'

连接

 $text = StringPlus::create('Lorem Ipsum')
            ->concat('')
            ->concat(null)
            ->concat('is simply dummy text of the printing and typesetting industry.')
            ->concat('');

结果

 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.'

 $isIn = StringPlus::create('Lorem Ipsum')->in('Ipsum');

 if($isIn === true){
    echo "OK.";
 }

获取长度

 $length = StringPlus::create('Lorem Ipsum')->getLength();

等于

 $isEquals = StringPlus::create('Lorem Ipsum')->equals('Lorem Ipsum');

 if($isIn === true){
    echo "Es igual.";
 }

转为md5

 $md5 = StringPlus::create('Lorem Ipsum')->toMd5();