tayron / string-object
此包的最新版本(1.0.0)没有提供许可证信息。
字符串操作类
1.0.0
2017-06-09 18:30 UTC
Requires
- php: >=5.3
- tayron/float-object: 1.0.0
- tayron/integer-object: 1.0.0
This package is not auto-updated.
Last update: 2024-09-29 04:20:12 UTC
README
字符串管理类
资源
- isEquals(StringObject $string) - 方法用于检查当前对象的内容是否与提供的StringObject对象的内容相同
- length() - 方法返回字符串的长度
- wordCount($format, $charlist) - 方法返回字符串中使用的单词数量
- parseIntegerObject() - 方法将StringObject对象转换为IntegerObject
- parseFloatObject() - 方法将StringObject对象转换为FloatObject
- parseArrayObject() - 方法将StringObject转换为ArrayObject
- replace(StringObject $search, StringObject $replace) - 方法用于搜索字符串并替换为另一个字符串
- format(ArrayObject $values) - 方法设置值以填充字符串中的键,其行为类似于sprintf设置值。
- toLowercase() - 方法将所有字母转换为小写
- toUppercase() - 方法将所有字母转换为大写
- toUppercaseWord($delimiters) - 方法将每个单词的第一个字符转换为大写
- trim($characterMask) - 方法移除字符串的开始和结尾空格
- utf8Encode() - 方法将ISO-8859-1字符串编码为UTF-8
- utf8Decode() - 方法将使用UTF-8编码的ISO-8859-1字符编码的字符串转换为单字节ISO-8859-1
通过composer使用
"require": { ... "tayron/string-object" : "1.0.0" ... },
使用示例
<?php use Tayron\StringObject; try{ $pedro = new StringObject('Pedro'); $maria = new StringObject('Pedro'); var_dump($pedro); var_dump($maria); var_dump($pedro->isEquals($maria)); var_dump($pedro->length()); $numero = new StringObject('123'); var_dump($numero); $numero = $numero->parseIntegerObject(); var_dump($numero); $numero = $numero->parseStringObject(); var_dump($numero); $numero->replace('3', '999'); var_dump($numero); $texto = new StringObject('Nome: %s , Idade %d anos'); echo $texto->format(new ArrayObject(array('Pedro', '15'))); // Nome: Pedro, Idade 15 anos echo $texto->format(new ArrayObject(array('Maria', '32'))); // Nome: Maria, Idade 32 anos $texto = new StringObject('O rato roeu a roupa do rei de Roma'); echo $texto->wordCount(); // 9 $string = new StringObject(); $string->fillString('748'); $string->fillString('.'); $string->fillString("012.356.356-88", 11, 0, StringObject::LEFT, array('.', '-')); $string->fillString(' '); $string->fillString("Maria Betânia da Silva", 15); $string->fillString("Rua C, número 35", 20); $string->fillString("Caixa ", 30); $string->fillString("000"); $string->removeAccentuation(); $string->toUppercase(); $linhaDigitavel1 = $string; $linhaDigitavel2 = $string; $linhaDigitavelComplata = $linhaDigitavel1 . PHP_EOL . $linhaDigitavel2; $arquivo = fopen('teste.txt', 'w'); fwrite($arquivo, $linhaDigitavelComplata); fclose($arquivo); Irá criar um arquivo txt com o conteúdo: 748.01235635688 MARIA BETANIA RUA C, NUMERO 35 CAIXA 000 748.01235635688 MARIA BETANIA RUA C, NUMERO 35 CAIXA 000 O que é útil para criar strings com várias informações concatenadas, como por exemplo, criar linha digitável de boleto }catch(\Exception $e){ echo $e->getMessage(); }