typedphp / string-functions
0.1.0
2014-12-15 18:35 UTC
Requires
- php: >=5.4.0
- typedphp/type-functions: *
Requires (Dev)
- phpunit/phpunit: 4.*
README
示例
use TypedPHP\Functions\StringFunctions; StringFunctions\endsWith("a long string", "string"); // true StringFunctions\replace("a long string", "long", "enormous"); // "a enormous string"
函数
startsWith(string $haystack, string $needle) → bool
endsWith(string $haystack, string $needle) → bool
indexOf(string $haystack, string $needle, int $offset = 0) → int
length(string $string) → int
matches(string $haystack, string $needle) → bool
replace(string $haystack, string|array $needle, string|array $replacement) → string
slice(string $string, int $offset = 0, int $limit = 0) → string
split(string $haystack, string|null $needle = null, int $limit = 0) → array
trim(string $haystack, string $needle) → string
trimLeft(string $haystack, string $needle) → string
trimRight(string $haystack, string $needle) → string
注意事项
- 每个
$needle
都可以是一个普通字符串或正则表达式字符串。
安装
❯ composer require "typedphp/string-functions:*"
测试
❯ composer create-project "typedphp/string-functions:*" . ❯ vendor/bin/phpunit