This repository was archived by the owner on Dec 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
string.inc
Tadatoshi Tokutake edited this page May 31, 2015
·
9 revisions
- wrap
- wrap_by_tag
- follow_join
- set_jp_encoding
- start_with
- end_with
- have_any
- str_replace_first
- split_at
- mb_str_split
- is_blank
- mb_trim
- have_mb_char
string wrap(string $string, string $wrapper)
- Return the string wrapped by
$wrapper. - Example:
var_dump(wrap('regex', '/')); // => /regex/string wrap_by_tag(string $string, string $tag, string $class = '')
- Return the string wrapped by html tags.
- Example:
var_dump(wrap_by_tag('hello, world!', 'p' )); // => '<p>hello, world!</p>'
var_dump(wrap_by_tag('hello, world!', 'p', 'main')); // => '<p class="main">hello, world!</p>'string follow_join(string $glue, array $pieces)
- Return
implode($glue, $pieces) . $glue. - Example:
var_dump(follow_join(PHP_EOL, ['one', 'two', 'three']));
// => one
// two
// threevoid set_jp_encoding(string $encoding = 'UTF-8')
- Set the character encoding of system and regular expression for Japanese.
- Notice: This function allow 'ISO-8859-1', 'ASCII', 'JIS', 'UTF-8', 'EUC-JP' and 'SJIS' as the first argument.
bool start_with(string $haystack, string $needle)
- Judge if
$haystackstarts with$needle. - Notice: If
$needleis the empty string, This function always returnstrue. - Example:
$haystack = 'hello, world!';
var_dump(start_with($haystack, 'hello')); // => true
var_dump(start_with($haystack, 'world')); // => falsebool end_with(string $haystack, string $needle)
- Judge if
$haystackends with$needle. - Notice: If
$needleis the empty string, This function always returnstrue. - Example:
$haystack = 'hello, world!';
var_dump(end_with($haystack, 'world!')); // => true
var_dump(end_with($haystack, 'hello,')); // => falsebool have_any(string $haystack, array $needles)
- Judge if
$haystackincludes any of$needles. - Example:
$haystack = 'hello, world!';
var_dump(match_any($haystack, ['hell' , 'heven'])); // => true
var_dump(match_any($haystack, ['devil', 'god' ])); // => falsestring str_replace_first(string $search, string $replace, string $subject)
- Return the string whose first matching part is replaced by
$replace. - Example:
var_dump('hay', 'yo', 'hay! hay! hay!'); // => "yo! hay! hay!"array split_at(string $string, int $at)
- Return the pair of strings split at the position of
$at. - Notice: If
$atis negative, ifs absolute value specifies the position counted from the end. - Example:
var_dump('blur', 0); // => ["", "blur"]
var_dump('blur', 1); // => ["b", "lur"]
var_dump('blur', -1); // => ["blu", "r"]array mb_str_split(string $string, int $width = 1)
- Return the array of strings split in
$width. - Notice:
$widthmust be positive. - Example:
var_dump('hello', 1); // => ["h", "e", "l", "l", "o"]
var_dump('hello', 2); // => ["he", "ll", "o"]bool is_blank(string $string)
- Judge if
$stringconsists of the blank characters. - Notice: Recommend to use this function under UTF-8.
- Example:
var_dump("\t \n"); // => truestring mb_trim(string $string)
- Return the string removed the blank characters of the both ends.
- Notice: Recommend to use this function under UTF-8.
- Example:
var_dump(mb_trim(" echo 'hello';\n")); // => "echo 'hello';"bool have_mb_char(string $string)
- Judge if
$stringhas the multibyte character. - Example:
var_dump(have_mb_char('日本語' )); // => true
var_dump(have_mb_char('English')); // => falseWelcome any issure or pull request!
Please contact me by mail to tadatoshi.tokutake@gmail.com if you have some questions!