🉑 Portable UTF-8 library - performance optimized (unicode) string functions for php.

Overview

Build Status Build status FOSSA Status codecov.io Codacy Badge Latest Stable Version Total Downloads License Donate to this project using PayPal Donate to this project using Patreon

🉑 Portable UTF-8

Description

It is written in PHP (PHP 7+) and can work without "mbstring", "iconv" or any other extra encoding php-extension on your server.

The benefit of Portable UTF-8 is that it is easy to use, easy to bundle. This library will also auto-detect your server environment and will use the installed php-extensions if they are available, so you will have the best possible performance.

As a fallback we will use Symfony Polyfills, if needed. (https://github.com/symfony/polyfill)

The project based on ...

Demo

Here you can test some basic functions from this library and you can compare some results with the native php function results.

Index

Alternative

If you like a more Object Oriented Way to edit strings, then you can take a look at voku/Stringy, it's a fork of "danielstjules/Stringy" but it used the "Portable UTF-8"-Class and some extra methods.

// Standard library
strtoupper('fòôbàř');       // 'FòôBàř'
strlen('fòôbàř');           // 10

// mbstring 
// WARNING: if you don't use a polyfill like "Portable UTF-8", you need to install the php-extension "mbstring" on your server
mb_strtoupper('fòôbàř');    // 'FÒÔBÀŘ'
mb_strlen('fòôbàř');        // '6'

// Portable UTF-8
use voku\helper\UTF8;
UTF8::strtoupper('fòôbàř');    // 'FÒÔBÀŘ'
UTF8::strlen('fòôbàř');        // '6'

// voku/Stringy
use Stringy\Stringy as S;
$stringy = S::create('fòôbàř');
$stringy->toUpperCase();    // 'FÒÔBÀŘ'
$stringy->length();         // '6'

Install "Portable UTF-8" via "composer require"

composer require voku/portable-utf8

If your project do not need some of the Symfony polyfills please use the replace section of your composer.json. This removes any overhead from these polyfills as they are no longer part of your project. e.g.:

{
  "replace": {
    "symfony/polyfill-php72": "1.99",
    "symfony/polyfill-iconv": "1.99",
    "symfony/polyfill-intl-grapheme": "1.99",
    "symfony/polyfill-intl-normalizer": "1.99",
    "symfony/polyfill-mbstring": "1.99"
  }
}

Why Portable UTF-8?

PHP 5 and earlier versions have no native Unicode support. To bridge the gap, there exist several extensions like "mbstring", "iconv" and "intl".

The problem with "mbstring" and others is that most of the time you cannot ensure presence of a specific one on a server. If you rely on one of these, your application is no more portable. This problem gets even severe for open source applications that have to run on different servers with different configurations. Considering these, I decided to write a library:

Requirements and Recommendations

  • No extensions are required to run this library. Portable UTF-8 only needs PCRE library that is available by default since PHP 4.2.0 and cannot be disabled since PHP 5.3.0. "\u" modifier support in PCRE for UTF-8 handling is not a must.
  • PHP 5.3 is the minimum requirement, and all later versions are fine with Portable UTF-8.
  • PHP 7.0 is the minimum requirement since version 4.0 of Portable UTF-8, otherwise composer will install an older version
  • PHP 8.0 support is also available and will adapt the behaviours of the native functions.
  • To speed up string handling, it is recommended that you have "mbstring" or "iconv" available on your server, as well as the latest version of PCRE library
  • Although Portable UTF-8 is easy to use; moving from native API to Portable UTF-8 may not be straight-forward for everyone. It is highly recommended that you do not update your scripts to include Portable UTF-8 or replace or change anything before you first know the reason and consequences. Most of the time, some native function may be all what you need.
  • There is also a shim for "mbstring", "iconv" and "intl", so you can use it also on shared webspace.

Info

Since version 5.4.26 this library will NOT force "UTF-8" by "bootstrap.php" anymore. If you need to enable this behavior you can define "PORTABLE_UTF8__ENABLE_AUTO_FILTER", before requiring the autoloader.

define('PORTABLE_UTF8__ENABLE_AUTO_FILTER', 1);

Before version 5.4.26 this behavior was enabled by default and you could disable it via "PORTABLE_UTF8__DISABLE_AUTO_FILTER", but the code had potential security vulnerabilities via injecting code while redirecting via header('Location .... This is the reason I decided to add this BC in a bug fix release, so that everybody using the current version will receive the security-fix.

Usage

Example 1: UTF8::cleanup()

  echo UTF8::cleanup('�Düsseldorf�');
  
  // will output:
  // Düsseldorf

Example 2: UTF8::strlen()

  $string = 'string <strong>with utf-8 chars åèä</strong> - doo-bee doo-bee dooh';

  echo strlen($string) . "\n<br />";
  echo UTF8::strlen($string) . "\n<br />";

  // will output:
  // 70
  // 67

  $string_test1 = strip_tags($string);
  $string_test2 = UTF8::strip_tags($string);

  echo strlen($string_test1) . "\n<br />";
  echo UTF8::strlen($string_test2) . "\n<br />";

  // will output:
  // 53
  // 50

Example 3: UTF8::fix_utf8()

  echo UTF8::fix_utf8('Düsseldorf');
  echo UTF8::fix_utf8('ä');
  
  // will output:
  // Düsseldorf
  // ä

Portable UTF-8 | API

The API from the "UTF8"-Class is written as small static methods that will match the default PHP-API.

Class methods

access add_bom_to_string array_change_key_case between
binary_to_str bom callback char_at
chars checkForSupport chr chr_map
chr_size_list chr_to_decimal chr_to_hex chunk_split
clean cleanup codepoints collapse_whitespace
count_chars css_identifier css_stripe_media_queries ctype_loaded
decimal_to_chr decode_mimeheader emoji_decode emoji_encode
emoji_from_country_code encode encode_mimeheader extract_text
file_get_contents file_has_bom filter filter_input
filter_input_array filter_var filter_var_array finfo_loaded
first_char fits_inside fix_simple_utf8 fix_utf8
getCharDirection getSupportInfo get_file_type get_random_string
get_unique_string has_lowercase has_uppercase has_whitespace
hex_to_chr hex_to_int html_encode html_entity_decode
html_escape html_stripe_empty_tags htmlentities htmlspecialchars
iconv_loaded int_to_hex intlChar_loaded intl_loaded
is_alpha is_alphanumeric is_ascii is_base64
is_binary is_binary_file is_blank is_bom
is_empty is_hexadecimal is_html is_json
is_lowercase is_printable is_punctuation is_serialized
is_uppercase is_url is_utf8 is_utf16
is_utf32 json_decode json_encode json_loaded
lcfirst lcwords ltrim max
max_chr_width mbstring_loaded min normalize_encoding
normalize_line_ending normalize_msword normalize_whitespace ord
parse_str pcre_utf8_support range rawurldecode
regex_replace remove_bom remove_duplicates remove_html
remove_html_breaks remove_invisible_characters remove_left remove_right
replace replace_all replace_diamond_question_mark rtrim
showSupport single_chr_html_encode spaces_to_tabs str_camelize
str_capitalize_name str_contains str_contains_all str_contains_any
str_dasherize str_delimit str_detect_encoding str_ends_with
str_ends_with_any str_ensure_left str_ensure_right str_humanize
str_iends_with str_iends_with_any str_insert str_ireplace
str_ireplace_beginning str_ireplace_ending str_istarts_with str_istarts_with_any
str_isubstr_after_first_separator str_isubstr_after_last_separator str_isubstr_before_first_separator str_isubstr_before_last_separator
str_isubstr_first str_isubstr_last str_last_char str_limit
str_limit_after_word str_longest_common_prefix str_longest_common_substring str_longest_common_suffix
str_matches_pattern str_obfuscate str_offset_exists str_offset_get
str_pad str_pad_both str_pad_left str_pad_right
str_repeat str_replace_beginning str_replace_ending str_replace_first
str_replace_last str_shuffle str_slice str_snakeize
str_sort str_split str_split_array str_split_pattern
str_starts_with str_starts_with_any str_substr_after_first_separator str_substr_after_last_separator
str_substr_before_first_separator str_substr_before_last_separator str_substr_first str_substr_last
str_surround str_titleize str_titleize_for_humans str_to_binary
str_to_lines str_to_words str_truncate str_truncate_safe
str_underscored str_upper_camelize str_word_count strcasecmp
strcmp strcspn string string_has_bom
strip_tags strip_whitespace stripos stripos_in_byte
stristr strlen strlen_in_byte strnatcasecmp
strnatcmp strncasecmp strncmp strpbrk
strpos strpos_in_byte strrchr strrev
strrichr strripos strripos_in_byte strrpos
strrpos_in_byte strspn strstr strstr_in_byte
strtocasefold strtolower strtoupper strtr
strwidth substr substr_compare substr_count
substr_count_in_byte substr_count_simple substr_ileft substr_in_byte
substr_iright substr_left substr_replace substr_right
swapCase symfony_polyfill_used tabs_to_spaces titlecase
to_ascii to_boolean to_filename to_int
to_iso8859 to_string to_utf8 to_utf8_string
trim ucfirst ucwords urldecode
utf8_decode utf8_encode whitespace_table words_limit
wordwrap wordwrap_per_line ws

access(string $str, int $pos, string $encoding): string

Return the character at the specified position: $str[1] like functionality.

EXAMPLE: UTF8::access('fòô', 1); // 'ò'

Parameters:

  • string $str <p>A UTF-8 string.</p>
  • int $pos <p>The position of character to return.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string <p>Single multi-byte character.</p>

add_bom_to_string(string $str): string

Prepends UTF-8 BOM character to the string and returns the whole string.

INFO: If BOM already existed there, the Input string is returned.

EXAMPLE: UTF8::add_bom_to_string('fòô'); // "\xEF\xBB\xBF" . 'fòô'

Parameters:

  • string $str <p>The input string.</p>

Return:

  • string <p>The output string that contains BOM.</p>

array_change_key_case(array $array, int $case, string $encoding): string[]

Changes all keys in an array.

Parameters:

  • array<string, mixed> $array <p>The array to work on</p>
  • int $case [optional] <p> Either <strong>CASE_UPPER</strong><br> or <strong>CASE_LOWER</strong> (default)</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string[] <p>An array with its keys lower- or uppercased.</p>

between(string $str, string $start, string $end, int $offset, string $encoding): string

Returns the substring between $start and $end, if found, or an empty string. An optional offset may be supplied from which to begin the search for the start string.

Parameters:

  • string $str
  • string $start <p>Delimiter marking the start of the substring.</p>
  • string $end <p>Delimiter marking the end of the substring.</p>
  • int $offset [optional] <p>Index from which to begin the search. Default: 0</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string

binary_to_str(string $bin): string

Convert binary into a string.

INFO: opposite to UTF8::str_to_binary()

EXAMPLE: UTF8::binary_to_str('11110000100111111001100010000011'); // '😃'

Parameters:

  • string $bin 1|0

Return:

  • string

bom(): string

Returns the UTF-8 Byte Order Mark Character.

INFO: take a look at UTF8::$bom for e.g. UTF-16 and UTF-32 BOM values

EXAMPLE: UTF8::bom(); // "\xEF\xBB\xBF"

Parameters: nothing

Return:

  • string <p>UTF-8 Byte Order Mark.</p>

callback(callable $callback, string $str): string[]

Parameters:

  • callable $callback
  • string $str

Return:

  • string[]

char_at(string $str, int $index, string $encoding): string

Returns the character at $index, with indexes starting at 0.

Parameters:

  • string $str <p>The input string.</p>
  • int $index <p>Position of the character.</p>
  • string $encoding [optional] <p>Default is UTF-8</p>

Return:

  • string <p>The character at $index.</p>

chars(string $str): string[]

Returns an array consisting of the characters in the string.

Parameters:

  • string $str <p>The input string.</p>

Return:

  • string[] <p>An array of chars.</p>

checkForSupport(): true|null

This method will auto-detect your server environment for UTF-8 support.

Parameters: nothing

Return:

  • true|null

chr(int $code_point, string $encoding): string|null

Generates a UTF-8 encoded character from the given code point.

INFO: opposite to UTF8::ord()

EXAMPLE: UTF8::chr(0x2603); // '☃'

Parameters:

  • int $code_point <p>The code point for which to generate a character.</p>
  • string $encoding [optional] <p>Default is UTF-8</p>

Return:

  • string|null <p>Multi-byte character, returns null on failure or empty input.</p>

chr_map(callable $callback, string $str): string[]

Applies callback to all characters of a string.

EXAMPLE: UTF8::chr_map([UTF8::class, 'strtolower'], 'Κόσμε'); // ['κ','ό', 'σ', 'μ', 'ε']

Parameters:

  • callable $callback <p>The callback function.</p>
  • string $str <p>UTF-8 string to run callback on.</p>

Return:

  • string[] <p>The outcome of the callback, as array.</p>

chr_size_list(string $str): int[]

Generates an array of byte length of each character of a Unicode string.

1 byte => U+0000 - U+007F 2 byte => U+0080 - U+07FF 3 byte => U+0800 - U+FFFF 4 byte => U+10000 - U+10FFFF

EXAMPLE: UTF8::chr_size_list('中文空白-test'); // [3, 3, 3, 3, 1, 1, 1, 1, 1]

Parameters:

  • string $str <p>The original unicode string.</p>

Return:

  • int[] <p>An array of byte lengths of each character.</p>

chr_to_decimal(string $char): int

Get a decimal code representation of a specific character.

INFO: opposite to UTF8::decimal_to_chr()

EXAMPLE: UTF8::chr_to_decimal('§'); // 0xa7

Parameters:

  • string $char <p>The input character.</p>

Return:

  • int

chr_to_hex(int|string $char, string $prefix): string

Get hexadecimal code point (U+xxxx) of a UTF-8 encoded character.

EXAMPLE: UTF8::chr_to_hex('§'); // U+00a7

Parameters:

  • int|string $char <p>The input character</p>
  • string $prefix [optional]

Return:

  • string <p>The code point encoded as U+xxxx.</p>

chunk_split(string $body, int $chunk_length, string $end): string

Splits a string into smaller chunks and multiple lines, using the specified line ending character.

EXAMPLE: UTF8::chunk_split('ABC-ÖÄÜ-中文空白-κόσμε', 3); // "ABC\r\n-ÖÄ\r\nÜ-中\r\n文空白\r\n-κό\r\nσμε"

Parameters:

  • string $body <p>The original string to be split.</p>
  • int $chunk_length [optional] <p>The maximum character length of a chunk.</p>
  • string $end [optional] <p>The character(s) to be inserted at the end of each chunk.</p>

Return:

  • string <p>The chunked string.</p>

clean(string $str, bool $remove_bom, bool $normalize_whitespace, bool $normalize_msword, bool $keep_non_breaking_space, bool $replace_diamond_question_mark, bool $remove_invisible_characters, bool $remove_invisible_characters_url_encoded): string

Accepts a string and removes all non-UTF-8 characters from it + extras if needed.

EXAMPLE: UTF8::clean("\xEF\xBB\xBF„Abcdef\xc2\xa0\x20…” — 😃 - Düsseldorf", true, true); // '„Abcdef  …” — 😃 - Düsseldorf'

Parameters:

  • string $str <p>The string to be sanitized.</p>
  • bool $remove_bom [optional] <p>Set to true, if you need to remove UTF-BOM.</p>
  • bool $normalize_whitespace [optional] <p>Set to true, if you need to normalize the whitespace.</p>
  • bool $normalize_msword [optional] <p>Set to true, if you need to normalize MS Word chars e.g.: "…" => "..."</p>
  • bool $keep_non_breaking_space [optional] <p>Set to true, to keep non-breaking-spaces, in combination with $normalize_whitespace</p>
  • bool $replace_diamond_question_mark [optional] <p>Set to true, if you need to remove diamond question mark e.g.: "�"</p>
  • bool $remove_invisible_characters [optional] <p>Set to false, if you not want to remove invisible characters e.g.: "\0"</p>
  • `bool $remove_invisible_characters_url_encoded [optional]

    Set to true, if you not want to remove invisible url encoded characters e.g.: "%0B"
    WARNING: maybe contains false-positives e.g. aa%0Baa -> aaaa.

`

Return:

  • string <p>An clean UTF-8 encoded string.</p>

cleanup(string $str): string

Clean-up a string and show only printable UTF-8 chars at the end + fix UTF-8 encoding.

EXAMPLE: UTF8::cleanup("\xEF\xBB\xBF„Abcdef\xc2\xa0\x20…” — 😃 - Düsseldorf", true, true); // '„Abcdef  …” — 😃 - Düsseldorf'

Parameters:

  • string $str <p>The input string.</p>

Return:

  • string

codepoints(string|string[] $arg, bool $use_u_style): int[]|string[]

Accepts a string or a array of strings and returns an array of Unicode code points.

INFO: opposite to UTF8::string()

EXAMPLE: UTF8::codepoints('κöñ'); // array(954, 246, 241) // ... OR ... UTF8::codepoints('κöñ', true); // array('U+03ba', 'U+00f6', 'U+00f1')

Parameters:

  • string|string[] $arg <p>A UTF-8 encoded string or an array of such strings.</p>
  • bool $use_u_style <p>If True, will return code points in U+xxxx format, default, code points will be returned as integers.</p>

Return:

  • `int[]|string[]

    The array of code points:
    int[] for $u_style === false
    string[] for $u_style === true

`

collapse_whitespace(string $str): string

Trims the string and replaces consecutive whitespace characters with a single space. This includes tabs and newline characters, as well as multibyte whitespace such as the thin space and ideographic space.

Parameters:

  • string $str <p>The input string.</p>

Return:

  • string <p>A string with trimmed $str and condensed whitespace.</p>

count_chars(string $str, bool $clean_utf8, bool $try_to_use_mb_functions): int[]

Returns count of characters used in a string.

EXAMPLE: UTF8::count_chars('κaκbκc'); // array('κ' => 3, 'a' => 1, 'b' => 1, 'c' => 1)

Parameters:

  • string $str <p>The input string.</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>
  • bool $try_to_use_mb_functions [optional] <p>Set to false, if you don't want to use

Return:

  • int[] <p>An associative array of Character as keys and their count as values.</p>

css_identifier(string $str, string[] $filter, bool $strip_tags, bool $strtolower): string

Create a valid CSS identifier for e.g. "class"- or "id"-attributes.

EXAMPLE: UTF8::css_identifier('123foo/bar!!!'); // _23foo-bar

copy&past from https://github.com/drupal/core/blob/8.8.x/lib/Drupal/Component/Utility/Html.php#L95

Parameters:

  • string $str <p>INFO: if no identifier is given e.g. " " or "", we will create a unique string automatically</p>
  • array<string, string> $filter
  • bool $strip_tags
  • bool $strtolower

Return:

  • string

css_stripe_media_queries(string $str): string

Remove css media-queries.

Parameters:

  • string $str

Return:

  • string

ctype_loaded(): bool

Checks whether ctype is available on the server.

Parameters: nothing

Return:

  • bool <p><strong>true</strong> if available, <strong>false</strong> otherwise</p>

decimal_to_chr(int|string $int): string

Converts an int value into a UTF-8 character.

INFO: opposite to UTF8::string()

EXAMPLE: UTF8::decimal_to_chr(931); // 'Σ'

Parameters:

  • int|numeric-string $int

Return:

  • string

decode_mimeheader(string $str, string $encoding): false|string

Decodes a MIME header field

Parameters:

  • string $str
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • false|string <p>A decoded MIME field on success, or false if an error occurs during the decoding.</p>

emoji_decode(string $str, bool $use_reversible_string_mappings): string

Decodes a string which was encoded by "UTF8::emoji_encode()".

INFO: opposite to UTF8::emoji_encode()

EXAMPLE: UTF8::emoji_decode('foo CHARACTER_OGRE', false); // 'foo 👹' // UTF8::emoji_decode('foo -PORTABLE_UTF8-308095726-627590803-8FTU_ELBATROP-', true); // 'foo 👹'

Parameters:

  • string $str <p>The input string.</p>
  • bool $use_reversible_string_mappings [optional] <p> When <b>TRUE</b>, we se a reversible string mapping between "emoji_encode" and "emoji_decode".</p>

Return:

  • string

emoji_encode(string $str, bool $use_reversible_string_mappings): string

Encode a string with emoji chars into a non-emoji string.

INFO: opposite to UTF8::emoji_decode()

EXAMPLE: UTF8::emoji_encode('foo 👹', false)); // 'foo CHARACTER_OGRE' // UTF8::emoji_encode('foo 👹', true)); // 'foo -PORTABLE_UTF8-308095726-627590803-8FTU_ELBATROP-'

Parameters:

  • string $str <p>The input string</p>
  • bool $use_reversible_string_mappings [optional] <p> when <b>TRUE</b>, we use a reversible string mapping between "emoji_encode" and "emoji_decode"</p>

Return:

  • string

emoji_from_country_code(string $country_code_iso_3166_1): string

Convert any two-letter country code (ISO 3166-1) to the corresponding Emoji.

Parameters:

  • string $country_code_iso_3166_1 <p>e.g. DE</p>

Return:

  • string <p>Emoji or empty string on error.</p>

encode(string $to_encoding, string $str, bool $auto_detect_the_from_encoding, string $from_encoding): string

Encode a string with a new charset-encoding.

INFO: This function will also try to fix broken / double encoding, so you can call this function also on a UTF-8 string and you don't mess up the string.

EXAMPLE: UTF8::encode('ISO-8859-1', '-ABC-中文空白-'); // '-ABC-????-' // UTF8::encode('UTF-8', '-ABC-中文空白-'); // '-ABC-中文空白-' // UTF8::encode('HTML', '-ABC-中文空白-'); // '-ABC-中文空白-' // UTF8::encode('BASE64', '-ABC-中文空白-'); // 'LUFCQy3kuK3mlofnqbrnmb0t'

Parameters:

  • string $to_encoding <p>e.g. 'UTF-16', 'UTF-8', 'ISO-8859-1', etc.</p>
  • string $str <p>The input string</p>
  • bool $auto_detect_the_from_encoding [optional] <p>Force the new encoding (we try to fix broken / double encoding for UTF-8)<br> otherwise we auto-detect the current string-encoding</p>
  • string $from_encoding [optional] <p>e.g. 'UTF-16', 'UTF-8', 'ISO-8859-1', etc.<br> A empty string will trigger the autodetect anyway.</p>

Return:

  • string

encode_mimeheader(string $str, string $from_charset, string $to_charset, string $transfer_encoding, string $linefeed, int $indent): false|string

Parameters:

  • string $str
  • string $from_charset [optional] <p>Set the input charset.</p>
  • string $to_charset [optional] <p>Set the output charset.</p>
  • string $transfer_encoding [optional] <p>Set the transfer encoding.</p>
  • string $linefeed [optional] <p>Set the used linefeed.</p>
  • int $indent [optional] <p>Set the max length indent.</p>

Return:

  • false|string <p>An encoded MIME field on success, or false if an error occurs during the encoding.</p>

extract_text(string $str, string $search, int|null $length, string $replacer_for_skipped_text, string $encoding): string

Create an extract from a sentence, so if the search-string was found, it try to centered in the output.

Parameters:

  • string $str <p>The input string.</p>
  • string $search <p>The searched string.</p>
  • int|null $length [optional] <p>Default: null === text->length / 2</p>
  • string $replacer_for_skipped_text [optional] <p>Default: …</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string

file_get_contents(string $filename, bool $use_include_path, resource|null $context, int|null $offset, int|null $max_length, int $timeout, bool $convert_to_utf8, string $from_encoding): false|string

Reads entire file into a string.

EXAMPLE: UTF8::file_get_contents('utf16le.txt'); // ...

WARNING: Do not use UTF-8 Option ($convert_to_utf8) for binary files (e.g.: images) !!!

Parameters:

  • `string $filename

    Name of the file to read.

` - `bool $use_include_path [optional]

Prior to PHP 5, this parameter is called use_include_path and is a bool. As of PHP 5 the FILE_USE_INCLUDE_PATH can be used to trigger include path search.

` - `resource|null $context [optional]

A valid context resource created with stream_context_create. If you don't need to use a custom context, you can skip this parameter by &null;.

` - `int|null $offset [optional]

The offset where the reading starts.

` - `int|null $max_length [optional]

Maximum length of data read. The default is to read until end of file is reached.

` - `int $timeout

The time in seconds for the timeout.

` - `bool $convert_to_utf8 WARNING!!!

Maybe you can't use this option for some files, because they used non default utf-8 chars. Binary files like images or pdf will not be converted.

` - `string $from_encoding [optional]

e.g. 'UTF-16', 'UTF-8', 'ISO-8859-1', etc.
A empty string will trigger the autodetect anyway.

`

Return:

  • false|string <p>The function returns the read data as string or <b>false</b> on failure.</p>

file_has_bom(string $file_path): bool

Checks if a file starts with BOM (Byte Order Mark) character.

EXAMPLE: UTF8::file_has_bom('utf8_with_bom.txt'); // true

Parameters:

  • string $file_path <p>Path to a valid file.</p>

Return:

  • bool <p><strong>true</strong> if the file has BOM at the start, <strong>false</strong> otherwise</p>

filter(array|object|string $var, int $normalization_form, string $leading_combining): mixed

Normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed.

EXAMPLE: UTF8::filter(array("\xE9", 'à', 'a')); // array('é', 'à', 'a')

Parameters:

  • TFilter $var
  • int $normalization_form
  • string $leading_combining

Return:

  • mixed

filter_input(int $type, string $variable_name, int $filter, int|int[]|null $options): mixed

"filter_input()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed.

Gets a specific external variable by name and optionally filters it.

EXAMPLE: // _GET['foo'] = 'bar'; UTF8::filter_input(INPUT_GET, 'foo', FILTER_SANITIZE_STRING)); // 'bar'

Parameters:

  • `int $type

    One of INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.

` - `string $variable_name

Name of a variable to get.

` - `int $filter [optional]

The ID of the filter to apply. The manual page lists the available filters.

` - `int|int[]|null $options [optional]

Associative array of options or bitwise disjunction of flags. If filter accepts options, flags can be provided in "flags" field of array.

`

Return:

  • `mixed

    Value of the requested variable on success, FALSE if the filter fails, or NULL if the variable_name variable is not set. If the flag FILTER_NULL_ON_FAILURE is used, it returns FALSE if the variable is not set and NULL if the filter fails.

`

filter_input_array(int $type, array|null $definition, bool $add_empty): mixed

"filter_input_array()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed.

Gets external variables and optionally filters them.

EXAMPLE: // _GET['foo'] = 'bar'; UTF8::filter_input_array(INPUT_GET, array('foo' => 'FILTER_SANITIZE_STRING')); // array('bar')

Parameters:

  • `int $type

    One of INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.

` - `array|null $definition [optional]

An array defining the arguments. A valid key is a string containing a variable name and a valid value is either a filter type, or an array optionally specifying the filter, flags and options. If the value is an array, valid keys are filter which specifies the filter type, flags which specifies any flags that apply to the filter, and options which specifies any options that apply to the filter. See the example below for a better understanding.

This parameter can be also an integer holding a filter constant. Then all values in the input array are filtered by this filter.

` - `bool $add_empty [optional]

Add missing keys as NULL to the return value.

`

Return:

  • `mixed

    An array containing the values of the requested variables on success, or FALSE on failure. An array value will be FALSE if the filter fails, or NULL if the variable is not set. Or if the flag FILTER_NULL_ON_FAILURE is used, it returns FALSE if the variable is not set and NULL if the filter fails.

`

filter_var(float|int|string|null $variable, int $filter, int|int[]|null $options): mixed

"filter_var()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed.

Filters a variable with a specified filter.

EXAMPLE: UTF8::filter_var('-ABC-中文空白-', FILTER_VALIDATE_URL); // false

Parameters:

  • `float|int|string|null $variable

    Value to filter.

` - `int $filter [optional]

The ID of the filter to apply. The manual page lists the available filters.

` - `int|int[]|null $options [optional]

Associative array of options or bitwise disjunction of flags. If filter accepts options, flags can be provided in "flags" field of array. For the "callback" filter, callable type should be passed. The callback must accept one argument, the value to be filtered, and return the value after filtering/sanitizing it.

// for filters that accept options, use this format $options = array( 'options' => array( 'default' => 3, // value to return if the filter fails // other options here 'min_range' => 0 ), 'flags' => FILTER_FLAG_ALLOW_OCTAL, ); $var = filter_var('0755', FILTER_VALIDATE_INT, $options); // for filter that only accept flags, you can pass them directly $var = filter_var('oops', FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); // for filter that only accept flags, you can also pass as an array $var = filter_var('oops', FILTER_VALIDATE_BOOLEAN, array('flags' => FILTER_NULL_ON_FAILURE)); // callback validate filter function foo($value) { // Expected format: Surname, GivenNames if (strpos($value, ", ") === false) return false; list($surname, $givennames) = explode(", ", $value, 2); $empty = (empty($surname) || empty($givennames)); $notstrings = (!is_string($surname) || !is_string($givennames)); if ($empty || $notstrings) { return false; } else { return $value; } } $var = filter_var('Doe, Jane Sue', FILTER_CALLBACK, array('options' => 'foo'));

`

Return:

  • mixed <p>The filtered data, or <b>FALSE</b> if the filter fails.</p>

filter_var_array(array $data, array|int|null $definition, bool $add_empty): mixed

"filter_var_array()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed.

Gets multiple variables and optionally filters them.

EXAMPLE: $filters = [ 'name' => ['filter' => FILTER_CALLBACK, 'options' => [UTF8::class, 'ucwords']], 'age' => ['filter' => FILTER_VALIDATE_INT, 'options' => ['min_range' => 1, 'max_range' => 120]], 'email' => FILTER_VALIDATE_EMAIL, ];

$data = [ 'name' => 'κόσμε', 'age' => '18', 'email' => '[email protected]' ];

UTF8::filter_var_array($data, $filters, true); // ['name' => 'Κόσμε', 'age' => 18, 'email' => '[email protected]']

Parameters:

  • `array $data

    An array with string keys containing the data to filter.

` - `array|int|null $definition [optional]

An array defining the arguments. A valid key is a string containing a variable name and a valid value is either a filter type, or an array optionally specifying the filter, flags and options. If the value is an array, valid keys are filter which specifies the filter type, flags which specifies any flags that apply to the filter, and options which specifies any options that apply to the filter. See the example below for a better understanding.

This parameter can be also an integer holding a filter constant. Then all values in the input array are filtered by this filter.

` - `bool $add_empty [optional]

Add missing keys as NULL to the return value.

`

Return:

  • `mixed

    An array containing the values of the requested variables on success, or FALSE on failure. An array value will be FALSE if the filter fails, or NULL if the variable is not set.

`

finfo_loaded(): bool

Checks whether finfo is available on the server.

Parameters: nothing

Return:

  • bool <p><strong>true</strong> if available, <strong>false</strong> otherwise</p>

first_char(string $str, int $n, string $encoding): string

Returns the first $n characters of the string.

Parameters:

  • string $str <p>The input string.</p>
  • int $n <p>Number of characters to retrieve from the start.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string

fits_inside(string $str, int $box_size): bool

Check if the number of Unicode characters isn't greater than the specified integer.

EXAMPLE: UTF8::fits_inside('κόσμε', 6); // false

Parameters:

  • string $str the original string to be checked
  • int $box_size the size in number of chars to be checked against string

Return:

  • bool <p><strong>TRUE</strong> if string is less than or equal to $box_size, <strong>FALSE</strong> otherwise.</p>

fix_simple_utf8(string $str): string

Try to fix simple broken UTF-8 strings.

INFO: Take a look at "UTF8::fix_utf8()" if you need a more advanced fix for broken UTF-8 strings.

EXAMPLE: UTF8::fix_simple_utf8('Düsseldorf'); // 'Düsseldorf'

If you received an UTF-8 string that was converted from Windows-1252 as it was ISO-8859-1 (ignoring Windows-1252 chars from 80 to 9F) use this function to fix it. See: http://en.wikipedia.org/wiki/Windows-1252

Parameters:

  • string $str <p>The input string</p>

Return:

  • string

fix_utf8(string|string[] $str): string|string[]

Fix a double (or multiple) encoded UTF8 string.

EXAMPLE: UTF8::fix_utf8('Fédération'); // 'Fédération'

Parameters:

  • string|string[] $str you can use a string or an array of strings

Return:

  • string|string[] Will return the fixed input-"array" or the fixed input-"string"

getCharDirection(string $char): string

Get character of a specific character.

EXAMPLE: UTF8::getCharDirection('ا'); // 'RTL'

Parameters:

  • string $char

Return:

  • string <p>'RTL' or 'LTR'.</p>

getSupportInfo(string|null $key): mixed

Check for php-support.

Parameters:

  • string|null $key

Return:

  • mixed Return the full support-"array", if $key === null<br> return bool-value, if $key is used and available<br> otherwise return <strong>null</strong>

get_file_type(string $str, array $fallback): null[]|string[]

Warning: this method only works for some file-types (png, jpg) if you need more supported types, please use e.g. "finfo"

Parameters:

  • string $str
  • array{ext: (null|string), mime: (null|string), type: (null|string)} $fallback <p>with this keys: 'ext', 'mime', 'type'

Return:

  • null[]|string[] <p>with this keys: 'ext', 'mime', 'type'</p>

get_random_string(int $length, string $possible_chars, string $encoding): string

Parameters:

  • int $length <p>Length of the random string.</p>
  • string $possible_chars [optional] <p>Characters string for the random selection.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string

get_unique_string(int|string $extra_entropy, bool $use_md5): string

Parameters:

  • int|string $extra_entropy [optional] <p>Extra entropy via a string or int value.</p>
  • bool $use_md5 [optional] <p>Return the unique identifier as md5-hash? Default: true</p>

Return:

  • string

has_lowercase(string $str): bool

Returns true if the string contains a lower case char, false otherwise.

Parameters:

  • string $str <p>The input string.</p>

Return:

  • bool <p>Whether or not the string contains a lower case character.</p>

has_uppercase(string $str): bool

Returns true if the string contains an upper case char, false otherwise.

Parameters:

  • string $str <p>The input string.</p>

Return:

  • bool <p>Whether or not the string contains an upper case character.</p>

has_whitespace(string $str): bool

Returns true if the string contains whitespace, false otherwise.

Parameters:

  • string $str <p>The input string.</p>

Return:

  • bool <p>Whether or not the string contains whitespace.</p>

hex_to_chr(string $hexdec): false|string

Converts a hexadecimal value into a UTF-8 character.

INFO: opposite to UTF8::chr_to_hex()

EXAMPLE: UTF8::hex_to_chr('U+00a7'); // '§'

Parameters:

  • string $hexdec <p>The hexadecimal value.</p>

Return:

  • false|string one single UTF-8 character

hex_to_int(string $hexdec): false|int

Converts hexadecimal U+xxxx code point representation to integer.

INFO: opposite to UTF8::int_to_hex()

EXAMPLE: UTF8::hex_to_int('U+00f1'); // 241

Parameters:

  • string $hexdec <p>The hexadecimal code point representation.</p>

Return:

  • false|int <p>The code point, or false on failure.</p>

html_encode(string $str, bool $keep_ascii_chars, string $encoding): string

Converts a UTF-8 string to a series of HTML numbered entities.

INFO: opposite to UTF8::html_decode()

EXAMPLE: UTF8::html_encode('中文空白'); // '中文空白'

Parameters:

  • string $str <p>The Unicode string to be encoded as numbered entities.</p>
  • bool $keep_ascii_chars [optional] <p>Keep ASCII chars.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string HTML numbered entities

html_entity_decode(string $str, int|null $flags, string $encoding): string

UTF-8 version of html_entity_decode()

The reason we are not using html_entity_decode() by itself is because while it is not technically correct to leave out the semicolon at the end of an entity most browsers will still interpret the entity correctly. html_entity_decode() does not convert entities without semicolons, so we are left with our own little solution here. Bummer.

Convert all HTML entities to their applicable characters.

INFO: opposite to UTF8::html_encode()

EXAMPLE: UTF8::html_entity_decode('中文空白'); // '中文空白'

Parameters:

  • `string $str

    The input string.

` - `int|null $flags [optional]

A bitmask of one or more of the following flags, which specify how to handle quotes and which document type to use. The default is ENT_COMPAT | ENT_HTML401.

Available flags constants
Constant Name Description
ENT_COMPAT Will convert double-quotes and leave single-quotes alone.
ENT_QUOTES Will convert both double and single quotes.
ENT_NOQUOTES Will leave both double and single quotes unconverted.
ENT_HTML401 Handle code as HTML 4.01.
ENT_XML1 Handle code as XML 1.
ENT_XHTML Handle code as XHTML.
ENT_HTML5 Handle code as HTML 5.

` - `string $encoding [optional]

Set the charset for e.g. "mb_" function

`

Return:

  • string the decoded string

html_escape(string $str, string $encoding): string

Create a escape html version of the string via "UTF8::htmlspecialchars()".

Parameters:

  • string $str
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string

html_stripe_empty_tags(string $str): string

Remove empty html-tag.

e.g.:


Parameters:

  • string $str

Return:

  • string

htmlentities(string $str, int $flags, string $encoding, bool $double_encode): string

Convert all applicable characters to HTML entities: UTF-8 version of htmlentities().

EXAMPLE: UTF8::htmlentities('<白-öäü>'); // '<白-öäü>'

Parameters:

  • `string $str

    The input string.

` - `int $flags [optional]

A bitmask of one or more of the following flags, which specify how to handle quotes, invalid code unit sequences and the used document type. The default is ENT_COMPAT | ENT_HTML401.

Available flags constants
Constant Name Description
ENT_COMPAT Will convert double-quotes and leave single-quotes alone.
ENT_QUOTES Will convert both double and single quotes.
ENT_NOQUOTES Will leave both double and single quotes unconverted.
ENT_IGNORE Silently discard invalid code unit sequences instead of returning an empty string. Using this flag is discouraged as it may have security implications.
ENT_SUBSTITUTE Replace invalid code unit sequences with a Unicode Replacement Character U+FFFD (UTF-8) or &#38;#FFFD; (otherwise) instead of returning an empty string.
ENT_DISALLOWED Replace invalid code points for the given document type with a Unicode Replacement Character U+FFFD (UTF-8) or &#38;#FFFD; (otherwise) instead of leaving them as is. This may be useful, for instance, to ensure the well-formedness of XML documents with embedded external content.
ENT_HTML401 Handle code as HTML 4.01.
ENT_XML1 Handle code as XML 1.
ENT_XHTML Handle code as XHTML.
ENT_HTML5 Handle code as HTML 5.

` - `string $encoding [optional]

Like htmlspecialchars, htmlentities takes an optional third argument encoding which defines encoding used in conversion. Although this argument is technically optional, you are highly encouraged to specify the correct value for your code.

` - `bool $double_encode [optional]

When double_encode is turned off PHP will not encode existing html entities. The default is to convert everything.

`

Return:

  • `string

    The encoded string.

    If the input string contains an invalid code unit sequence within the given encoding an empty string will be returned, unless either the ENT_IGNORE or ENT_SUBSTITUTE flags are set.

`

htmlspecialchars(string $str, int $flags, string $encoding, bool $double_encode): string

Convert only special characters to HTML entities: UTF-8 version of htmlspecialchars()

INFO: Take a look at "UTF8::htmlentities()"

EXAMPLE: UTF8::htmlspecialchars('<白-öäü>'); // '<白-öäü>'

Parameters:

  • `string $str

    The string being converted.

` - `int $flags [optional]

A bitmask of one or more of the following flags, which specify how to handle quotes, invalid code unit sequences and the used document type. The default is ENT_COMPAT | ENT_HTML401.

Available flags constants
Constant Name Description
ENT_COMPAT Will convert double-quotes and leave single-quotes alone.
ENT_QUOTES Will convert both double and single quotes.
ENT_NOQUOTES Will leave both double and single quotes unconverted.
ENT_IGNORE Silently discard invalid code unit sequences instead of returning an empty string. Using this flag is discouraged as it may have security implications.
ENT_SUBSTITUTE Replace invalid code unit sequences with a Unicode Replacement Character U+FFFD (UTF-8) or &#38;#FFFD; (otherwise) instead of returning an empty string.
ENT_DISALLOWED Replace invalid code points for the given document type with a Unicode Replacement Character U+FFFD (UTF-8) or &#38;#FFFD; (otherwise) instead of leaving them as is. This may be useful, for instance, to ensure the well-formedness of XML documents with embedded external content.
ENT_HTML401 Handle code as HTML 4.01.
ENT_XML1 Handle code as XML 1.
ENT_XHTML Handle code as XHTML.
ENT_HTML5 Handle code as HTML 5.

` - `string $encoding [optional]

Defines encoding used in conversion.

For the purposes of this function, the encodings ISO-8859-1, ISO-8859-15, UTF-8, cp866, cp1251, cp1252, and KOI8-R are effectively equivalent, provided the string itself is valid for the encoding, as the characters affected by htmlspecialchars occupy the same positions in all of these encodings.

` - `bool $double_encode [optional]

When double_encode is turned off PHP will not encode existing html entities, the default is to convert everything.

`

Return:

  • `string the converted string.

If the input string contains an invalid code unit sequence within the given encoding an empty string will be returned, unless either the ENT_IGNORE or ENT_SUBSTITUTE flags are set`


iconv_loaded(): bool

Checks whether iconv is available on the server.

Parameters: nothing

Return:

  • bool <p><strong>true</strong> if available, <strong>false</strong> otherwise</p>

int_to_hex(int $int, string $prefix): string

Converts Integer to hexadecimal U+xxxx code point representation.

INFO: opposite to UTF8::hex_to_int()

EXAMPLE: UTF8::int_to_hex(241); // 'U+00f1'

Parameters:

  • int $int <p>The integer to be converted to hexadecimal code point.</p>
  • string $prefix [optional]

Return:

  • string the code point, or empty string on failure

intlChar_loaded(): bool

Checks whether intl-char is available on the server.

Parameters: nothing

Return:

  • bool <p><strong>true</strong> if available, <strong>false</strong> otherwise</p>

intl_loaded(): bool

Checks whether intl is available on the server.

Parameters: nothing

Return:

  • bool <p><strong>true</strong> if available, <strong>false</strong> otherwise</p>

is_alpha(string $str): bool

Returns true if the string contains only alphabetic chars, false otherwise.

Parameters:

  • string $str <p>The input string.</p>

Return:

  • bool <p>Whether or not $str contains only alphabetic chars.</p>

is_alphanumeric(string $str): bool

Returns true if the string contains only alphabetic and numeric chars, false otherwise.

Parameters:

  • string $str <p>The input string.</p>

Return:

  • bool <p>Whether or not $str contains only alphanumeric chars.</p>

is_ascii(string $str): bool

Checks if a string is 7 bit ASCII.

EXAMPLE: UTF8::is_ascii('白'); // false

Parameters:

  • string $str <p>The string to check.</p>

Return:

  • `bool

    true if it is ASCII
    false otherwise

`

is_base64(string|null $str, bool $empty_string_is_valid): bool

Returns true if the string is base64 encoded, false otherwise.

EXAMPLE: UTF8::is_base64('4KSu4KWL4KSo4KS/4KSa'); // true

Parameters:

  • string|null $str <p>The input string.</p>
  • bool $empty_string_is_valid [optional] <p>Is an empty string valid base64 or not?</p>

Return:

  • bool <p>Whether or not $str is base64 encoded.</p>

is_binary(int|string $input, bool $strict): bool

Check if the input is binary.

.. (is look like a hack).

EXAMPLE: UTF8::is_binary(01); // true

Parameters:

  • int|string $input
  • bool $strict

Return:

  • bool

is_binary_file(string $file): bool

Check if the file is binary.

EXAMPLE: UTF8::is_binary('./utf32.txt'); // true

Parameters:

  • string $file

Return:

  • bool

is_blank(string $str): bool

Returns true if the string contains only whitespace chars, false otherwise.

Parameters:

  • string $str <p>The input string.</p>

Return:

  • bool <p>Whether or not $str contains only whitespace characters.</p>

is_bom(string $str): bool

Checks if the given string is equal to any "Byte Order Mark".

WARNING: Use "UTF8::string_has_bom()" if you will check BOM in a string.

EXAMPLE: UTF8::is_bom("\xef\xbb\xbf"); // true

Parameters:

  • string $str <p>The input string.</p>

Return:

  • bool <p><strong>true</strong> if the $utf8_chr is Byte Order Mark, <strong>false</strong> otherwise.</p>

is_empty(array|float|int|string $str): bool

Determine whether the string is considered to be empty.

A variable is considered empty if it does not exist or if its value equals FALSE. empty() does not generate a warning if the variable does not exist.

Parameters:

  • array|float|int|string $str

Return:

  • bool <p>Whether or not $str is empty().</p>

is_hexadecimal(string $str): bool

Returns true if the string contains only hexadecimal chars, false otherwise.

Parameters:

  • string $str <p>The input string.</p>

Return:

  • bool <p>Whether or not $str contains only hexadecimal chars.</p>

is_html(string $str): bool

Check if the string contains any HTML tags.

EXAMPLE: UTF8::is_html('lall'); // true

Parameters:

  • string $str <p>The input string.</p>

Return:

  • bool <p>Whether or not $str contains html elements.</p>

is_json(string $str, bool $only_array_or_object_results_are_valid): bool

Try to check if "$str" is a JSON-string.

EXAMPLE: UTF8::is_json('{"array":[1,"¥","ä"]}'); // true

Parameters:

  • string $str <p>The input string.</p>
  • bool $only_array_or_object_results_are_valid [optional] <p>Only array and objects are valid json results.</p>

Return:

  • bool <p>Whether or not the $str is in JSON format.</p>

is_lowercase(string $str): bool

Parameters:

  • string $str <p>The input string.</p>

Return:

  • bool <p>Whether or not $str contains only lowercase chars.</p>

is_printable(string $str, bool $ignore_control_characters): bool

Returns true if the string contains only printable (non-invisible) chars, false otherwise.

Parameters:

  • string $str <p>The input string.</p>
  • bool $ignore_control_characters [optional] <p>Ignore control characters like [LRM] or [LSEP].</p>

Return:

  • bool <p>Whether or not $str contains only printable (non-invisible) chars.</p>

is_punctuation(string $str): bool

Returns true if the string contains only punctuation chars, false otherwise.

Parameters:

  • string $str <p>The input string.</p>

Return:

  • bool <p>Whether or not $str contains only punctuation chars.</p>

is_serialized(string $str): bool

Returns true if the string is serialized, false otherwise.

Parameters:

  • string $str <p>The input string.</p>

Return:

  • bool <p>Whether or not $str is serialized.</p>

is_uppercase(string $str): bool

Returns true if the string contains only lower case chars, false otherwise.

Parameters:

  • string $str <p>The input string.</p>

Return:

  • bool <p>Whether or not $str contains only lower case characters.</p>

is_url(string $url, bool $disallow_localhost): bool

Check if $url is an correct url.

Parameters:

  • string $url
  • bool $disallow_localhost

Return:

  • bool

is_utf8(int|string|string[]|null $str, bool $strict): bool

Checks whether the passed input contains only byte sequences that appear valid UTF-8.

EXAMPLE: UTF8::is_utf8(['Iñtërnâtiônàlizætiøn', 'foo']); // true // UTF8::is_utf8(["Iñtërnâtiônàlizætiøn\xA0\xA1", 'bar']); // false

Parameters:

  • int|string|string[]|null $str <p>The input to be checked.</p>
  • bool $strict <p>Check also if the string is not UTF-16 or UTF-32.</p>

Return:

  • bool

is_utf16(string $str, bool $check_if_string_is_binary): false|int

Check if the string is UTF-16.

EXAMPLE: UTF8::is_utf16(file_get_contents('utf-16-le.txt')); // 1 // UTF8::is_utf16(file_get_contents('utf-16-be.txt')); // 2 // UTF8::is_utf16(file_get_contents('utf-8.txt')); // false

Parameters:

  • string $str <p>The input string.</p>
  • bool $check_if_string_is_binary

Return:

  • false|int <strong>false</strong> if is't not UTF-16,<br> <strong>1</strong> for UTF-16LE,<br> <strong>2</strong> for UTF-16BE

is_utf32(string $str, bool $check_if_string_is_binary): false|int

Check if the string is UTF-32.

EXAMPLE: UTF8::is_utf32(file_get_contents('utf-32-le.txt')); // 1 // UTF8::is_utf32(file_get_contents('utf-32-be.txt')); // 2 // UTF8::is_utf32(file_get_contents('utf-8.txt')); // false

Parameters:

  • string $str <p>The input string.</p>
  • bool $check_if_string_is_binary

Return:

  • false|int <strong>false</strong> if is't not UTF-32,<br> <strong>1</strong> for UTF-32LE,<br> <strong>2</strong> for UTF-32BE

json_decode(string $json, bool $assoc, int $depth, int $options): mixed

(PHP 5 >= 5.2.0, PECL json >= 1.2.0)
Decodes a JSON string

EXAMPLE: UTF8::json_decode('[1,"\u00a5","\u00e4"]'); // array(1, '¥', 'ä')

Parameters:

  • `string $json

    The json string being decoded.

This function only works with UTF-8 encoded strings.

PHP implements a superset of JSON - it will also encode and decode scalar types and NULL. The JSON standard only supports these values when they are nested inside an array or an object.

` - `bool $assoc [optional]

When TRUE, returned objects will be converted into associative arrays.

` - `int $depth [optional]

User specified recursion depth.

` - `int $options [optional]

Bitmask of JSON decode options. Currently only JSON_BIGINT_AS_STRING is supported (default is to cast large integers as floats)

`

Return:

  • mixed <p>The value encoded in <i>json</i> in appropriate PHP type. Values true, false and null (case-insensitive) are returned as <b>TRUE</b>, <b>FALSE</b> and <b>NULL</b> respectively. <b>NULL</b> is returned if the <i>json</i> cannot be decoded or if the encoded data is deeper than the recursion limit.</p>

json_encode(mixed $value, int $options, int $depth): false|string

(PHP 5 >= 5.2.0, PECL json >= 1.2.0)
Returns the JSON representation of a value.

EXAMPLE: UTF8::json_enocde(array(1, '¥', 'ä')); // '[1,"\u00a5","\u00e4"]'

Parameters:

  • `mixed $value

    The value being encoded. Can be any type except a resource.

All string data must be UTF-8 encoded.

PHP implements a superset of JSON - it will also encode and decode scalar types and NULL. The JSON standard only supports these values when they are nested inside an array or an object.

` - `int $options [optional]

Bitmask consisting of JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT, JSON_UNESCAPED_UNICODE. The behaviour of these constants is described on the JSON constants page.

` - `int $depth [optional]

Set the maximum depth. Must be greater than zero.

`

Return:

  • false|string A JSON encoded <strong>string</strong> on success or<br> <strong>FALSE</strong> on failure

json_loaded(): bool

Checks whether JSON is available on the server.

Parameters: nothing

Return:

  • bool <p><strong>true</strong> if available, <strong>false</strong> otherwise</p>

lcfirst(string $str, string $encoding, bool $clean_utf8, string|null $lang, bool $try_to_keep_the_string_length): string

Makes string's first char lowercase.

EXAMPLE: UTF8::lcfirst('ÑTËRNÂTIÔNÀLIZÆTIØN'); // ñTËRNÂTIÔNÀLIZÆTIØN

Parameters:

  • string $str <p>The input string</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>
  • string|null $lang [optional] <p>Set the language for special cases: az, el, lt, tr</p>
  • bool $try_to_keep_the_string_length [optional] <p>true === try to keep the string length: e.g. ẞ -> ß</p>

Return:

  • string the resulting string

lcwords(string $str, string[] $exceptions, string $char_list, string $encoding, bool $clean_utf8, string|null $lang, bool $try_to_keep_the_string_length): string

Lowercase for all words in the string.

Parameters:

  • string $str <p>The input string.</p>
  • string[] $exceptions [optional] <p>Exclusion for some words.</p>
  • string $char_list [optional] <p>Additional chars that contains to words and do not start a new word.</p>
  • string $encoding [optional] <p>Set the charset.</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>
  • string|null $lang [optional] <p>Set the language for special cases: az, el, lt, tr</p>
  • bool $try_to_keep_the_string_length [optional] <p>true === try to keep the string length: e.g. ẞ -> ß</p>

Return:

  • string

ltrim(string $str, string|null $chars): string

Strip whitespace or other characters from the beginning of a UTF-8 string.

EXAMPLE: UTF8::ltrim(' 中文空白  '); // '中文空白  '

Parameters:

  • string $str <p>The string to be trimmed</p>
  • string|null $chars <p>Optional characters to be stripped</p>

Return:

  • string the string with unwanted characters stripped from the left

max(string[]|string $arg): string|null

Returns the UTF-8 character with the maximum code point in the given data.

EXAMPLE: UTF8::max('abc-äöü-中文空白'); // 'ø'

Parameters:

  • string[]|string $arg <p>A UTF-8 encoded string or an array of such strings.</p>

Return:

  • string|null the character with the highest code point than others, returns null on failure or empty input

max_chr_width(string $str): int

Calculates and returns the maximum number of bytes taken by any UTF-8 encoded character in the given string.

EXAMPLE: UTF8::max_chr_width('Intërnâtiônàlizætiøn'); // 2

Parameters:

  • string $str <p>The original Unicode string.</p>

Return:

  • int <p>Max byte lengths of the given chars.</p>

mbstring_loaded(): bool

Checks whether mbstring is available on the server.

Parameters: nothing

Return:

  • bool <p><strong>true</strong> if available, <strong>false</strong> otherwise</p>

min(string|string[] $arg): string|null

Returns the UTF-8 character with the minimum code point in the given data.

EXAMPLE: UTF8::min('abc-äöü-中文空白'); // '-'

Parameters:

  • string|string[] $arg <strong>A UTF-8 encoded string or an array of such strings.</strong>

Return:

  • string|null <p>The character with the lowest code point than others, returns null on failure or empty input.</p>

normalize_encoding(mixed $encoding, mixed $fallback): mixed|string

Normalize the encoding-"name" input.

EXAMPLE: UTF8::normalize_encoding('UTF8'); // 'UTF-8'

Parameters:

  • mixed $encoding <p>e.g.: ISO, UTF8, WINDOWS-1251 etc.</p>
  • string|TNormalizeEncodingFallback $fallback <p>e.g.: UTF-8</p>

Return:

  • mixed|string <p>e.g.: ISO-8859-1, UTF-8, WINDOWS-1251 etc.<br>Will return a empty string as fallback (by default)</p>

normalize_line_ending(string $str, string|string[] $replacer): string

Standardize line ending to unix-like.

Parameters:

  • string $str <p>The input string.</p>
  • string|string[] $replacer <p>The replacer char e.g. "\n" (Linux) or "\r\n" (Windows). You can also use \PHP_EOL here.</p>

Return:

  • string <p>A string with normalized line ending.</p>

normalize_msword(string $str): string

Normalize some MS Word special characters.

EXAMPLE: UTF8::normalize_msword('„Abcdef…”'); // '"Abcdef..."'

Parameters:

  • string $str <p>The string to be normalized.</p>

Return:

  • string <p>A string with normalized characters for commonly used chars in Word documents.</p>

normalize_whitespace(string $str, bool $keep_non_breaking_space, bool $keep_bidi_unicode_controls, bool $normalize_control_characters): string

Normalize the whitespace.

EXAMPLE: UTF8::normalize_whitespace("abc-\xc2\xa0-öäü-\xe2\x80\xaf-\xE2\x80\xAC", true); // "abc-\xc2\xa0-öäü- -"

Parameters:

  • string $str <p>The string to be normalized.</p>
  • bool $keep_non_breaking_space [optional] <p>Set to true, to keep non-breaking-spaces.</p>
  • bool $keep_bidi_unicode_controls [optional] <p>Set to true, to keep non-printable (for the web) bidirectional text chars.</p>
  • bool $normalize_control_characters [optional] <p>Set to true, to convert e.g. LINE-, PARAGRAPH-SEPARATOR with "\n" and LINE TABULATION with "\t".</p>

Return:

  • string <p>A string with normalized whitespace.</p>

ord(string $chr, string $encoding): int

Calculates Unicode code point of the given UTF-8 encoded character.

INFO: opposite to UTF8::chr()

EXAMPLE: UTF8::ord('☃'); // 0x2603

Parameters:

  • string $chr <p>The character of which to calculate code point.<p/>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • int <p>Unicode code point of the given character,<br> 0 on invalid UTF-8 byte sequence</p>

parse_str(string $str, array $result, bool $clean_utf8): bool

Parses the string into an array (into the the second parameter).

WARNING: Unlike "parse_str()", this method does not (re-)place variables in the current scope, if the second parameter is not set!

EXAMPLE: UTF8::parse_str('Iñtërnâtiônéàlizætiøn=測試&arr[]=foo+測試&arr[]=ການທົດສອບ', $array); echo $array['Iñtërnâtiônéàlizætiøn']; // '測試'

Parameters:

  • string $str <p>The input string.</p>
  • array $result <p>The result will be returned into this reference parameter.</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>

Return:

  • bool <p>Will return <strong>false</strong> if php can't parse the string and we haven't any $result.</p>

pcre_utf8_support(): bool

Checks if \u modifier is available that enables Unicode support in PCRE.

Parameters: nothing

Return:

  • `bool

    true if support is available,
    false otherwise

`

range(int|string $var1, int|string $var2, bool $use_ctype, string $encoding, float|int $step): string[]

Create an array containing a range of UTF-8 characters.

EXAMPLE: UTF8::range('κ', 'ζ'); // array('κ', 'ι', 'θ', 'η', 'ζ',)

Parameters:

  • int|string $var1 <p>Numeric or hexadecimal code points, or a UTF-8 character to start from.</p>
  • int|string $var2 <p>Numeric or hexadecimal code points, or a UTF-8 character to end at.</p>
  • bool $use_ctype <p>use ctype to detect numeric and hexadecimal, otherwise we will use a simple "is_numeric"</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>
  • `float|int $step [optional]

    If a step value is given, it will be used as the increment between elements in the sequence. step should be given as a positive number. If not specified, step will default to 1.

`

Return:

  • string[]

rawurldecode(string $str, bool $multi_decode): string

Multi decode HTML entity + fix urlencoded-win1252-chars.

EXAMPLE: UTF8::rawurldecode('tes%20öäü%20\u00edtest+test'); // 'tes öäü ítest+test'

e.g: 'test+test' => 'test+test' 'Düsseldorf' => 'Düsseldorf' 'D%FCsseldorf' => 'Düsseldorf' 'Düsseldorf' => 'Düsseldorf' 'D%26%23xFC%3Bsseldorf' => 'Düsseldorf' 'Düsseldorf' => 'Düsseldorf' 'D%C3%BCsseldorf' => 'Düsseldorf' 'D%C3%83%C2%BCsseldorf' => 'Düsseldorf' 'D%25C3%2583%25C2%25BCsseldorf' => 'Düsseldorf'

Parameters:

  • string $str <p>The input string.</p>
  • bool $multi_decode <p>Decode as often as possible.</p>

Return:

  • string <p>The decoded URL, as a string.</p>

regex_replace(string $str, string $pattern, string $replacement, string $options, string $delimiter): string

Replaces all occurrences of $pattern in $str by $replacement.

Parameters:

  • string $str <p>The input string.</p>
  • string $pattern <p>The regular expression pattern.</p>
  • string $replacement <p>The string to replace with.</p>
  • string $options [optional] <p>Matching conditions to be used.</p>
  • string $delimiter [optional] <p>Delimiter the the regex. Default: '/'</p>

Return:

  • string

remove_bom(string $str): string

Remove the BOM from UTF-8 / UTF-16 / UTF-32 strings.

EXAMPLE: UTF8::remove_bom("\xEF\xBB\xBFΜπορώ να"); // 'Μπορώ να'

Parameters:

  • string $str <p>The input string.</p>

Return:

  • string <p>A string without UTF-BOM.</p>

remove_duplicates(string $str, string|string[] $what): string

Removes duplicate occurrences of a string in another string.

EXAMPLE: UTF8::remove_duplicates('öäü-κόσμεκόσμε-äöü', 'κόσμε'); // 'öäü-κόσμε-äöü'

Parameters:

  • string $str <p>The base string.</p>
  • string|string[] $what <p>String to search for in the base string.</p>

Return:

  • string <p>A string with removed duplicates.</p>

remove_html(string $str, string $allowable_tags): string

Remove html via "strip_tags()" from the string.

Parameters:

  • string $str <p>The input string.</p>
  • `string $allowable_tags [optional]

    You can use the optional second parameter to specify tags which should not be stripped. Default: null

`

Return:

  • string <p>A string with without html tags.</p>

remove_html_breaks(string $str, string $replacement): string

Remove all breaks [
| \r\n | \r | \n | .

..] from the string.

Parameters:

  • string $str <p>The input string.</p>
  • string $replacement [optional] <p>Default is a empty string.</p>

Return:

  • string <p>A string without breaks.</p>

remove_invisible_characters(string $str, bool $url_encoded, string $replacement, bool $keep_basic_control_characters): string

Remove invisible characters from a string.

e.g.: This prevents sandwiching null characters between ascii characters, like Java\0script.

EXAMPLE: UTF8::remove_invisible_characters("κόσ\0με"); // 'κόσμε'

copy&past from https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/Common.php

Parameters:

  • string $str <p>The input string.</p>
  • `bool $url_encoded [optional]

    Try to remove url encoded control character. WARNING: maybe contains false-positives e.g. aa%0Baa -> aaaa.


Default: false

` - `string $replacement [optional]

The replacement character.

` - `bool $keep_basic_control_characters [optional]

Keep control characters like [LRM] or [LSEP].

`

Return:

  • string <p>A string without invisible chars.</p>

remove_left(string $str, string $substring, string $encoding): string

Returns a new string with the prefix $substring removed, if present.

Parameters:

  • string $str <p>The input string.</p>
  • string $substring <p>The prefix to remove.</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>

Return:

  • string <p>A string without the prefix $substring.</p>

remove_right(string $str, string $substring, string $encoding): string

Returns a new string with the suffix $substring removed, if present.

Parameters:

  • string $str
  • string $substring <p>The suffix to remove.</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>

Return:

  • string <p>A string having a $str without the suffix $substring.</p>

replace(string $str, string $search, string $replacement, bool $case_sensitive): string

Replaces all occurrences of $search in $str by $replacement.

Parameters:

  • string $str <p>The input string.</p>
  • string $search <p>The needle to search for.</p>
  • string $replacement <p>The string to replace with.</p>
  • bool $case_sensitive [optional] <p>Whether or not to enforce case-sensitivity. Default: true</p>

Return:

  • string <p>A string with replaced parts.</p>

replace_all(string $str, array $search, array|string $replacement, bool $case_sensitive): string

Replaces all occurrences of $search in $str by $replacement.

Parameters:

  • string $str <p>The input string.</p>
  • array $search <p>The elements to search for.</p>
  • array|string $replacement <p>The string to replace with.</p>
  • bool $case_sensitive [optional] <p>Whether or not to enforce case-sensitivity. Default: true</p>

Return:

  • string <p>A string with replaced parts.</p>

replace_diamond_question_mark(string $str, string $replacement_char, bool $process_invalid_utf8_chars): string

Replace the diamond question mark (�) and invalid-UTF8 chars with the replacement.

EXAMPLE: UTF8::replace_diamond_question_mark('中文空白�', ''); // '中文空白'

Parameters:

  • string $str <p>The input string</p>
  • string $replacement_char <p>The replacement character.</p>
  • bool $process_invalid_utf8_chars <p>Convert invalid UTF-8 chars </p>

Return:

  • string <p>A string without diamond question marks (�).</p>

rtrim(string $str, string|null $chars): string

Strip whitespace or other characters from the end of a UTF-8 string.

EXAMPLE: UTF8::rtrim('-ABC-中文空白- '); // '-ABC-中文空白-'

Parameters:

  • string $str <p>The string to be trimmed.</p>
  • string|null $chars <p>Optional characters to be stripped.</p>

Return:

  • string <p>A string with unwanted characters stripped from the right.</p>

showSupport(bool $useEcho): string|void

WARNING: Print native UTF-8 support (libs) by default, e.g. for debugging.

Parameters:

  • bool $useEcho

Return:

  • string|void

single_chr_html_encode(string $char, bool $keep_ascii_chars, string $encoding): string

Converts a UTF-8 character to HTML Numbered Entity like "{".

EXAMPLE: UTF8::single_chr_html_encode('κ'); // 'κ'

Parameters:

  • string $char <p>The Unicode character to be encoded as numbered entity.</p>
  • bool $keep_ascii_chars <p>Set to <strong>true</strong> to keep ASCII chars.</>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string <p>The HTML numbered entity for the given character.</p>

spaces_to_tabs(string $str, int $tab_length): string

Parameters:

  • string $str
  • int $tab_length

Return:

  • string

str_camelize(string $str, string $encoding, bool $clean_utf8, string|null $lang, bool $try_to_keep_the_string_length): string

Returns a camelCase version of the string. Trims surrounding spaces, capitalizes letters following digits, spaces, dashes and underscores, and removes spaces, dashes, as well as underscores.

Parameters:

  • string $str <p>The input string.</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>
  • string|null $lang [optional] <p>Set the language for special cases: az, el, lt, tr</p>
  • bool $try_to_keep_the_string_length [optional] <p>true === try to keep the string length: e.g. ẞ -> ß</p>

Return:

  • string

str_capitalize_name(string $str): string

Returns the string with the first letter of each word capitalized, except for when the word is a name which shouldn't be capitalized.

Parameters:

  • string $str

Return:

  • string <p>A string with $str capitalized.</p>

str_contains(string $haystack, string $needle, bool $case_sensitive): bool

Returns true if the string contains $needle, false otherwise. By default the comparison is case-sensitive, but can be made insensitive by setting $case_sensitive to false.

Parameters:

  • string $haystack <p>The input string.</p>
  • string $needle <p>Substring to look for.</p>
  • bool $case_sensitive [optional] <p>Whether or not to enforce case-sensitivity. Default: true</p>

Return:

  • bool <p>Whether or not $haystack contains $needle.</p>

str_contains_all(string $haystack, array $needles, bool $case_sensitive): bool

Returns true if the string contains all $needles, false otherwise. By default the comparison is case-sensitive, but can be made insensitive by setting $case_sensitive to false.

Parameters:

  • string $haystack <p>The input string.</p>
  • array $needles <p>SubStrings to look for.</p>
  • bool $case_sensitive [optional] <p>Whether or not to enforce case-sensitivity. Default: true</p>

Return:

  • bool <p>Whether or not $haystack contains $needle.</p>

str_contains_any(string $haystack, array $needles, bool $case_sensitive): bool

Returns true if the string contains any $needles, false otherwise. By default the comparison is case-sensitive, but can be made insensitive by setting $case_sensitive to false.

Parameters:

  • string $haystack <p>The input string.</p>
  • array $needles <p>SubStrings to look for.</p>
  • bool $case_sensitive [optional] <p>Whether or not to enforce case-sensitivity. Default: true</p>

Return:

  • bool <p>Whether or not $str contains $needle.</p>

str_dasherize(string $str, string $encoding): string

Returns a lowercase and trimmed string separated by dashes. Dashes are inserted before uppercase characters (with the exception of the first character of the string), and in place of spaces as well as underscores.

Parameters:

  • string $str <p>The input string.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string

str_delimit(string $str, string $delimiter, string $encoding, bool $clean_utf8, string|null $lang, bool $try_to_keep_the_string_length): string

Returns a lowercase and trimmed string separated by the given delimiter.

Delimiters are inserted before uppercase characters (with the exception of the first character of the string), and in place of spaces, dashes, and underscores. Alpha delimiters are not converted to lowercase.

Parameters:

  • string $str <p>The input string.</p>
  • string $delimiter <p>Sequence used to separate parts of the string.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>
  • string|null $lang [optional] <p>Set the language for special cases: az, el, lt, tr</p>
  • bool $try_to_keep_the_string_length [optional] <p>true === try to keep the string length: e.g. ẞ -> ß</p>

Return:

  • string

str_detect_encoding(string $str): false|string

Optimized "mb_detect_encoding()"-function -> with support for UTF-16 and UTF-32.

EXAMPLE: UTF8::str_detect_encoding('中文空白'); // 'UTF-8' UTF8::str_detect_encoding('Abc'); // 'ASCII'

Parameters:

  • string $str <p>The input string.</p>

Return:

  • `false|string

    The detected string-encoding e.g. UTF-8 or UTF-16BE,
    otherwise it will return false e.g. for BINARY or not detected encoding.

`

str_ends_with(string $haystack, string $needle): bool

Check if the string ends with the given substring.

EXAMPLE: UTF8::str_ends_with('BeginMiddleΚόσμε', 'Κόσμε'); // true UTF8::str_ends_with('BeginMiddleΚόσμε', 'κόσμε'); // false

Parameters:

  • string $haystack <p>The string to search in.</p>
  • string $needle <p>The substring to search for.</p>

Return:

  • bool

str_ends_with_any(string $str, string[] $substrings): bool

Returns true if the string ends with any of $substrings, false otherwise.

  • case-sensitive

Parameters:

  • string $str <p>The input string.</p>
  • string[] $substrings <p>Substrings to look for.</p>

Return:

  • bool <p>Whether or not $str ends with $substring.</p>

str_ensure_left(string $str, string $substring): string

Ensures that the string begins with $substring. If it doesn't, it's prepended.

Parameters:

  • string $str <p>The input string.</p>
  • string $substring <p>The substring to add if not present.</p>

Return:

  • string

str_ensure_right(string $str, string $substring): string

Ensures that the string ends with $substring. If it doesn't, it's appended.

Parameters:

  • string $str <p>The input string.</p>
  • string $substring <p>The substring to add if not present.</p>

Return:

  • string

str_humanize(string $str): string

Capitalizes the first word of the string, replaces underscores with spaces, and strips '_id'.

Parameters:

  • string $str

Return:

  • string

str_iends_with(string $haystack, string $needle): bool

Check if the string ends with the given substring, case-insensitive.

EXAMPLE: UTF8::str_iends_with('BeginMiddleΚόσμε', 'Κόσμε'); // true UTF8::str_iends_with('BeginMiddleΚόσμε', 'κόσμε'); // true

Parameters:

  • string $haystack <p>The string to search in.</p>
  • string $needle <p>The substring to search for.</p>

Return:

  • bool

str_iends_with_any(string $str, string[] $substrings): bool

Returns true if the string ends with any of $substrings, false otherwise.

  • case-insensitive

Parameters:

  • string $str <p>The input string.</p>
  • string[] $substrings <p>Substrings to look for.</p>

Return:

  • bool <p>Whether or not $str ends with $substring.</p>

str_insert(string $str, string $substring, int $index, string $encoding): string

Inserts $substring into the string at the $index provided.

Parameters:

  • string $str <p>The input string.</p>
  • string $substring <p>String to be inserted.</p>
  • int $index <p>The index at which to insert the substring.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string

str_ireplace(string|string[] $search, string|string[] $replacement, string|string[] $subject, int $count): string|string[]

Case-insensitive and UTF-8 safe version of str_replace.

EXAMPLE: UTF8::str_ireplace('lIzÆ', 'lise', 'Iñtërnâtiônàlizætiøn'); // 'Iñtërnâtiônàlisetiøn'

Parameters:

  • `string|string[] $search

    Every replacement with search array is performed on the result of previous replacement.

` - `string|string[] $replacement

The replacement.

` - `TStrIReplaceSubject $subject

If subject is an array, then the search and replace is performed with every entry of subject, and the return value is an array as well.

` - `int $count [optional]

The number of matched and replaced needles will be returned in count which is passed by reference.

`

Return:

  • string|string[] <p>A string or an array of replacements.</p>

str_ireplace_beginning(string $str, string $search, string $replacement): string

Replaces $search from the beginning of string with $replacement.

Parameters:

  • string $str <p>The input string.</p>
  • string $search <p>The string to search for.</p>
  • string $replacement <p>The replacement.</p>

Return:

  • string <p>The string after the replacement.</p>

str_ireplace_ending(string $str, string $search, string $replacement): string

Replaces $search from the ending of string with $replacement.

Parameters:

  • string $str <p>The input string.</p>
  • string $search <p>The string to search for.</p>
  • string $replacement <p>The replacement.</p>

Return:

  • string <p>The string after the replacement.</p>

str_istarts_with(string $haystack, string $needle): bool

Check if the string starts with the given substring, case-insensitive.

EXAMPLE: UTF8::str_istarts_with('ΚόσμεMiddleEnd', 'Κόσμε'); // true UTF8::str_istarts_with('ΚόσμεMiddleEnd', 'κόσμε'); // true

Parameters:

  • string $haystack <p>The string to search in.</p>
  • string $needle <p>The substring to search for.</p>

Return:

  • bool

str_istarts_with_any(string $str, array $substrings): bool

Returns true if the string begins with any of $substrings, false otherwise.

  • case-insensitive

Parameters:

  • string $str <p>The input string.</p>
  • array $substrings <p>Substrings to look for.</p>

Return:

  • bool <p>Whether or not $str starts with $substring.</p>

str_isubstr_after_first_separator(string $str, string $separator, string $encoding): string

Gets the substring after the first occurrence of a separator.

Parameters:

  • string $str <p>The input string.</p>
  • string $separator <p>The string separator.</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>

Return:

  • string

str_isubstr_after_last_separator(string $str, string $separator, string $encoding): string

Gets the substring after the last occurrence of a separator.

Parameters:

  • string $str <p>The input string.</p>
  • string $separator <p>The string separator.</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>

Return:

  • string

str_isubstr_before_first_separator(string $str, string $separator, string $encoding): string

Gets the substring before the first occurrence of a separator.

Parameters:

  • string $str <p>The input string.</p>
  • string $separator <p>The string separator.</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>

Return:

  • string

str_isubstr_before_last_separator(string $str, string $separator, string $encoding): string

Gets the substring before the last occurrence of a separator.

Parameters:

  • string $str <p>The input string.</p>
  • string $separator <p>The string separator.</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>

Return:

  • string

str_isubstr_first(string $str, string $needle, bool $before_needle, string $encoding): string

Gets the substring after (or before via "$before_needle") the first occurrence of the "$needle".

Parameters:

  • string $str <p>The input string.</p>
  • string $needle <p>The string to look for.</p>
  • bool $before_needle [optional] <p>Default: false</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>

Return:

  • string

str_isubstr_last(string $str, string $needle, bool $before_needle, string $encoding): string

Gets the substring after (or before via "$before_needle") the last occurrence of the "$needle".

Parameters:

  • string $str <p>The input string.</p>
  • string $needle <p>The string to look for.</p>
  • bool $before_needle [optional] <p>Default: false</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>

Return:

  • string

str_last_char(string $str, int $n, string $encoding): string

Returns the last $n characters of the string.

Parameters:

  • string $str <p>The input string.</p>
  • int $n <p>Number of characters to retrieve from the end.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string

str_limit(string $str, int $length, string $str_add_on, string $encoding): string

Limit the number of characters in a string.

Parameters:

  • string $str <p>The input string.</p>
  • int $length [optional] <p>Default: 100</p>
  • string $str_add_on [optional] <p>Default: …</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string

str_limit_after_word(string $str, int $length, string $str_add_on, string $encoding): string

Limit the number of characters in a string, but also after the next word.

EXAMPLE: UTF8::str_limit_after_word('fòô bàř fòô', 8, ''); // 'fòô bàř'

Parameters:

  • string $str <p>The input string.</p>
  • int $length [optional] <p>Default: 100</p>
  • string $str_add_on [optional] <p>Default: …</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string

str_longest_common_prefix(string $str1, string $str2, string $encoding): string

Returns the longest common prefix between the $str1 and $str2.

Parameters:

  • string $str1 <p>The input sting.</p>
  • string $str2 <p>Second string for comparison.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string

str_longest_common_substring(string $str1, string $str2, string $encoding): string

Returns the longest common substring between the $str1 and $str2.

In the case of ties, it returns that which occurs first.

Parameters:

  • string $str1
  • string $str2 <p>Second string for comparison.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string <p>A string with its $str being the longest common substring.</p>

str_longest_common_suffix(string $str1, string $str2, string $encoding): string

Returns the longest common suffix between the $str1 and $str2.

Parameters:

  • string $str1
  • string $str2 <p>Second string for comparison.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string

str_matches_pattern(string $str, string $pattern): bool

Returns true if $str matches the supplied pattern, false otherwise.

Parameters:

  • string $str <p>The input string.</p>
  • string $pattern <p>Regex pattern to match against.</p>

Return:

  • bool <p>Whether or not $str matches the pattern.</p>

str_obfuscate(string $str, float $percent, string $obfuscateChar, string[] $keepChars): string

Convert a string into a obfuscate string.

EXAMPLE:

UTF8::str_obfuscate('[email protected]', 0.5, '', ['@', '.']); // e.g. "l**@m**lleke*.r"

Parameters:

  • string $str
  • float $percent
  • string $obfuscateChar
  • string[] $keepChars

Return:

  • string <p>The obfuscate string.</p>

str_offset_exists(string $str, int $offset, string $encoding): bool

Returns whether or not a character exists at an index. Offsets may be negative to count from the last character in the string. Implements part of the ArrayAccess interface.

Parameters:

  • string $str <p>The input string.</p>
  • int $offset <p>The index to check.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • bool <p>Whether or not the index exists.</p>

str_offset_get(string $str, int $index, string $encoding): string

Returns the character at the given index. Offsets may be negative to count from the last character in the string. Implements part of the ArrayAccess interface, and throws an OutOfBoundsException if the index does not exist.

Parameters:

  • string $str <p>The input string.</p>
  • int $index <p>The <strong>index</strong> from which to retrieve the char.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string <p>The character at the specified index.</p>

str_pad(string $str, int $pad_length, string $pad_string, int|string $pad_type, string $encoding): string

Pad a UTF-8 string to a given length with another string.

EXAMPLE: UTF8::str_pad('中文空白', 10, '_', STR_PAD_BOTH); // '中文空白'

Parameters:

  • string $str <p>The input string.</p>
  • int $pad_length <p>The length of return string.</p>
  • string $pad_string [optional] <p>String to use for padding the input string.</p>
  • `int|string $pad_type [optional]

    Can be STR_PAD_RIGHT (default), [or string "right"]
    STR_PAD_LEFT [or string "left"] or
    STR_PAD_BOTH [or string "both"]

` - `string $encoding [optional]

Default: 'UTF-8'

`

Return:

  • string <p>Returns the padded string.</p>

str_pad_both(string $str, int $length, string $pad_str, string $encoding): string

Returns a new string of a given length such that both sides of the string are padded. Alias for "UTF8::str_pad()" with a $pad_type of 'both'.

Parameters:

  • string $str
  • int $length <p>Desired string length after padding.</p>
  • string $pad_str [optional] <p>String used to pad, defaults to space. Default: ' '</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string <p>The string with padding applied.</p>

str_pad_left(string $str, int $length, string $pad_str, string $encoding): string

Returns a new string of a given length such that the beginning of the string is padded. Alias for "UTF8::str_pad()" with a $pad_type of 'left'.

Parameters:

  • string $str
  • int $length <p>Desired string length after padding.</p>
  • string $pad_str [optional] <p>String used to pad, defaults to space. Default: ' '</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string <p>The string with left padding.</p>

str_pad_right(string $str, int $length, string $pad_str, string $encoding): string

Returns a new string of a given length such that the end of the string is padded. Alias for "UTF8::str_pad()" with a $pad_type of 'right'.

Parameters:

  • string $str
  • int $length <p>Desired string length after padding.</p>
  • string $pad_str [optional] <p>String used to pad, defaults to space. Default: ' '</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string <p>The string with right padding.</p>

str_repeat(string $str, int $multiplier): string

Repeat a string.

EXAMPLE: UTF8::str_repeat("°~\xf0\x90\x28\xbc", 2); // '°ð�(¼°ð�(¼'

Parameters:

  • `string $str

    The string to be repeated.

` - `int $multiplier

Number of time the input string should be repeated.

multiplier has to be greater than or equal to 0. If the multiplier is set to 0, the function will return an empty string.

`

Return:

  • string <p>The repeated string.</p>

str_replace_beginning(string $str, string $search, string $replacement): string

Replaces $search from the beginning of string with $replacement.

Parameters:

  • string $str <p>The input string.</p>
  • string $search <p>The string to search for.</p>
  • string $replacement <p>The replacement.</p>

Return:

  • string <p>A string after the replacements.</p>

str_replace_ending(string $str, string $search, string $replacement): string

Replaces $search from the ending of string with $replacement.

Parameters:

  • string $str <p>The input string.</p>
  • string $search <p>The string to search for.</p>
  • string $replacement <p>The replacement.</p>

Return:

  • string <p>A string after the replacements.</p>

str_replace_first(string $search, string $replace, string $subject): string

Replace the first "$search"-term with the "$replace"-term.

Parameters:

  • string $search
  • string $replace
  • string $subject

Return:

  • string

str_replace_last(string $search, string $replace, string $subject): string

Replace the last "$search"-term with the "$replace"-term.

Parameters:

  • string $search
  • string $replace
  • string $subject

Return:

  • string

str_shuffle(string $str, string $encoding): string

Shuffles all the characters in the string.

INFO: uses random algorithm which is weak for cryptography purposes

EXAMPLE: UTF8::str_shuffle('fòô bàř fòô'); // 'àòôřb ffòô '

Parameters:

  • string $str <p>The input string</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string <p>The shuffled string.</p>

str_slice(string $str, int $start, int|null $end, string $encoding): false|string

Returns the substring beginning at $start, and up to, but not including the index specified by $end. If $end is omitted, the function extracts the remaining string. If $end is negative, it is computed from the end of the string.

Parameters:

  • string $str
  • int $start <p>Initial index from which to begin extraction.</p>
  • int|null $end [optional] <p>Index at which to end extraction. Default: null</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • false|string <p>The extracted substring.</p><p>If <i>str</i> is shorter than <i>start</i> characters long, <b>FALSE</b> will be returned.

str_snakeize(string $str, string $encoding): string

Convert a string to e.g.: "snake_case"

Parameters:

  • string $str
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string <p>A string in snake_case.</p>

str_sort(string $str, bool $unique, bool $desc): string

Sort all characters according to code points.

EXAMPLE: UTF8::str_sort(' -ABC-中文空白- '); // ' ---ABC中文白空'

Parameters:

  • string $str <p>A UTF-8 string.</p>
  • bool $unique <p>Sort unique. If <strong>true</strong>, repeated characters are ignored.</p>
  • bool $desc <p>If <strong>true</strong>, will sort characters in reverse code point order.</p>

Return:

  • string <p>A string of sorted characters.</p>

str_split(int|string $input, int $length, bool $clean_utf8, bool $try_to_use_mb_functions): string[]

Convert a string to an array of unicode characters.

EXAMPLE: UTF8::str_split('中文空白'); // array('中', '文', '空', '白')

Parameters:

  • int|string $input <p>The string or int to split into array.</p>
  • int $length [optional] <p>Max character length of each array element.</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>
  • bool $try_to_use_mb_functions [optional] <p>Set to false, if you don't want to use "mb_substr"</p>

Return:

  • string[] <p>An array containing chunks of chars from the input.</p>

str_split_array(int[]|string[] $input, int $length, bool $clean_utf8, bool $try_to_use_mb_functions): string[][]

Convert a string to an array of Unicode characters.

EXAMPLE: UTF8::str_split_array(['中文空白', 'test'], 2); // [['中文', '空白'], ['te', 'st']]

Parameters:

  • int[]|string[] $input <p>The string[] or int[] to split into array.</p>
  • int $length [optional] <p>Max character length of each array lement.</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>
  • bool $try_to_use_mb_functions [optional] <p>Set to false, if you don't want to use "mb_substr"</p>

Return:

  • string[][] <p>An array containing chunks of the input.</p>

str_split_pattern(string $str, string $pattern, int $limit): string[]

Splits the string with the provided regular expression, returning an array of strings. An optional integer $limit will truncate the results.

Parameters:

  • string $str
  • string $pattern <p>The regex with which to split the string.</p>
  • int $limit [optional] <p>Maximum number of results to return. Default: -1 === no limit</p>

Return:

  • string[] <p>An array of strings.</p>

str_starts_with(string $haystack, string $needle): bool

Check if the string starts with the given substring.

EXAMPLE: UTF8::str_starts_with('ΚόσμεMiddleEnd', 'Κόσμε'); // true UTF8::str_starts_with('ΚόσμεMiddleEnd', 'κόσμε'); // false

Parameters:

  • string $haystack <p>The string to search in.</p>
  • string $needle <p>The substring to search for.</p>

Return:

  • bool

str_starts_with_any(string $str, array $substrings): bool

Returns true if the string begins with any of $substrings, false otherwise.

  • case-sensitive

Parameters:

  • string $str <p>The input string.</p>
  • array $substrings <p>Substrings to look for.</p>

Return:

  • bool <p>Whether or not $str starts with $substring.</p>

str_substr_after_first_separator(string $str, string $separator, string $encoding): string

Gets the substring after the first occurrence of a separator.

Parameters:

  • string $str <p>The input string.</p>
  • string $separator <p>The string separator.</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>

Return:

  • string

str_substr_after_last_separator(string $str, string $separator, string $encoding): string

Gets the substring after the last occurrence of a separator.

Parameters:

  • string $str <p>The input string.</p>
  • string $separator <p>The string separator.</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>

Return:

  • string

str_substr_before_first_separator(string $str, string $separator, string $encoding): string

Gets the substring before the first occurrence of a separator.

Parameters:

  • string $str <p>The input string.</p>
  • string $separator <p>The string separator.</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>

Return:

  • string

str_substr_before_last_separator(string $str, string $separator, string $encoding): string

Gets the substring before the last occurrence of a separator.

Parameters:

  • string $str <p>The input string.</p>
  • string $separator <p>The string separator.</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>

Return:

  • string

str_substr_first(string $str, string $needle, bool $before_needle, string $encoding): string

Gets the substring after (or before via "$before_needle") the first occurrence of the "$needle".

Parameters:

  • string $str <p>The input string.</p>
  • string $needle <p>The string to look for.</p>
  • bool $before_needle [optional] <p>Default: false</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>

Return:

  • string

str_substr_last(string $str, string $needle, bool $before_needle, string $encoding): string

Gets the substring after (or before via "$before_needle") the last occurrence of the "$needle".

Parameters:

  • string $str <p>The input string.</p>
  • string $needle <p>The string to look for.</p>
  • bool $before_needle [optional] <p>Default: false</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>

Return:

  • string

str_surround(string $str, string $substring): string

Surrounds $str with the given substring.

Parameters:

  • string $str
  • string $substring <p>The substring to add to both sides.</p>

Return:

  • string <p>A string with the substring both prepended and appended.</p>

str_titleize(string $str, array|string[]|null $ignore, string $encoding, bool $clean_utf8, string|null $lang, bool $try_to_keep_the_string_length, bool $use_trim_first, string|null $word_define_chars): string

Returns a trimmed string with the first letter of each word capitalized.

Also accepts an array, $ignore, allowing you to list words not to be capitalized.

Parameters:

  • string $str
  • array|string[]|null $ignore [optional] <p>An array of words not to capitalize or null. Default: null</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>
  • string|null $lang [optional] <p>Set the language for special cases: az, el, lt, tr</p>
  • bool $try_to_keep_the_string_length [optional] <p>true === try to keep the string length: e.g. ẞ -> ß</p>
  • bool $use_trim_first [optional] <p>true === trim the input string, first</p>
  • string|null $word_define_chars [optional] <p>An string of chars that will be used as whitespace separator === words.</p>

Return:

  • string <p>The titleized string.</p>

str_titleize_for_humans(string $str, array $ignore, string $encoding): string

Returns a trimmed string in proper title case.

Also accepts an array, $ignore, allowing you to list words not to be capitalized.

Adapted from John Gruber's script.

Parameters:

  • string $str
  • array $ignore <p>An array of words not to capitalize.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string <p>The titleized string.</p>

str_to_binary(string $str): false|string

Get a binary representation of a specific string.

EXAPLE: UTF8::str_to_binary('😃'); // '11110000100111111001100010000011'

Parameters:

  • string $str <p>The input string.</p>

Return:

  • false|string <p>false on error</p>

str_to_lines(string $str, bool $remove_empty_values, int|null $remove_short_values): string[]

Parameters:

  • string $str
  • bool $remove_empty_values <p>Remove empty values.</p>
  • int|null $remove_short_values <p>The min. string length or null to disable</p>

Return:

  • string[]

str_to_words(string $str, string $char_list, bool $remove_empty_values, int|null $remove_short_values): string[]

Convert a string into an array of words.

EXAMPLE: UTF8::str_to_words('中文空白 oöäü#s', '#') // array('', '中文空白', ' ', 'oöäü#s', '')

Parameters:

  • string $str
  • string $char_list <p>Additional chars for the definition of "words".</p>
  • bool $remove_empty_values <p>Remove empty values.</p>
  • int|null $remove_short_values <p>The min. string length or null to disable</p>

Return:

  • string[]

str_truncate(string $str, int $length, string $substring, string $encoding): string

Truncates the string to a given length. If $substring is provided, and truncating occurs, the string is further truncated so that the substring may be appended without exceeding the desired length.

Parameters:

  • string $str
  • int $length <p>Desired length of the truncated string.</p>
  • string $substring [optional] <p>The substring to append if it can fit. Default: ''</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>

Return:

  • string <p>A string after truncating.</p>

str_truncate_safe(string $str, int $length, string $substring, string $encoding, bool $ignore_do_not_split_words_for_one_word): string

Truncates the string to a given length, while ensuring that it does not split words. If $substring is provided, and truncating occurs, the string is further truncated so that the substring may be appended without exceeding the desired length.

Parameters:

  • string $str
  • int $length <p>Desired length of the truncated string.</p>
  • string $substring [optional] <p>The substring to append if it can fit. Default: ''</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>
  • bool $ignore_do_not_split_words_for_one_word [optional] <p>Default: false</p>

Return:

  • string <p>A string after truncating.</p>

str_underscored(string $str): string

Returns a lowercase and trimmed string separated by underscores.

Underscores are inserted before uppercase characters (with the exception of the first character of the string), and in place of spaces as well as dashes.

Parameters:

  • string $str

Return:

  • string <p>The underscored string.</p>

str_upper_camelize(string $str, string $encoding, bool $clean_utf8, string|null $lang, bool $try_to_keep_the_string_length): string

Returns an UpperCamelCase version of the supplied string. It trims surrounding spaces, capitalizes letters following digits, spaces, dashes and underscores, and removes spaces, dashes, underscores.

Parameters:

  • string $str <p>The input string.</p>
  • string $encoding [optional] <p>Default: 'UTF-8'</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>
  • string|null $lang [optional] <p>Set the language for special cases: az, el, lt, tr</p>
  • bool $try_to_keep_the_string_length [optional] <p>true === try to keep the string length: e.g. ẞ -> ß</p>

Return:

  • string <p>A string in UpperCamelCase.</p>

str_word_count(string $str, int $format, string $char_list): int|string[]

Get the number of words in a specific string.

EXAMPLES: // format: 0 -> return only word count (int) // UTF8::str_word_count('中文空白 öäü abc#c'); // 4 UTF8::str_word_count('中文空白 öäü abc#c', 0, '#'); // 3

// format: 1 -> return words (array) // UTF8::str_word_count('中文空白 öäü abc#c', 1); // array('中文空白', 'öäü', 'abc', 'c') UTF8::str_word_count('中文空白 öäü abc#c', 1, '#'); // array('中文空白', 'öäü', 'abc#c')

// format: 2 -> return words with offset (array) // UTF8::str_word_count('中文空白 öäü ab#c', 2); // array(0 => '中文空白', 5 => 'öäü', 9 => 'abc', 13 => 'c') UTF8::str_word_count('中文空白 öäü ab#c', 2, '#'); // array(0 => '中文空白', 5 => 'öäü', 9 => 'abc#c')

Parameters:

  • string $str <p>The input string.</p>
  • `int $format [optional]

    0 => return a number of words (default)
    1 => return an array of words
    2 => return an array of words with word-offset as key

` - `string $char_list [optional]

Additional chars that contains to words and do not start a new word.

`

Return:

  • int|string[] <p>The number of words in the string.</p>

strcasecmp(string $str1, string $str2, string $encoding): int

Case-insensitive string comparison.

INFO: Case-insensitive version of UTF8::strcmp()

EXAMPLE: UTF8::strcasecmp("iñtërnâtiôn\nàlizætiøn", "Iñtërnâtiôn\nàlizætiøn"); // 0

Parameters:

  • string $str1 <p>The first string.</p>
  • string $str2 <p>The second string.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • int <strong>&lt; 0</strong> if str1 is less than str2;<br> <strong>&gt; 0</strong> if str1 is greater than str2,<br> <strong>0</strong> if they are equal

strcmp(string $str1, string $str2): int

Case-sensitive string comparison.

EXAMPLE: UTF8::strcmp("iñtërnâtiôn\nàlizætiøn", "iñtërnâtiôn\nàlizætiøn"); // 0

Parameters:

  • string $str1 <p>The first string.</p>
  • string $str2 <p>The second string.</p>

Return:

  • int <strong>&lt; 0</strong> if str1 is less than str2<br> <strong>&gt; 0</strong> if str1 is greater than str2<br> <strong>0</strong> if they are equal

strcspn(string $str, string $char_list, int $offset, int|null $length, string $encoding): int

Find length of initial segment not matching mask.

Parameters:

  • string $str
  • string $char_list
  • int $offset
  • int|null $length
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • int

string(int|int[]|string|string[] $intOrHex): string

Create a UTF-8 string from code points.

INFO: opposite to UTF8::codepoints()

EXAMPLE: UTF8::string(array(246, 228, 252)); // 'öäü'

Parameters:

  • int[]|numeric-string[]|int|numeric-string $intOrHex <p>Integer or Hexadecimal codepoints.</p>

Return:

  • string <p>A UTF-8 encoded string.</p>

string_has_bom(string $str): bool

Checks if string starts with "BOM" (Byte Order Mark Character) character.

EXAMPLE: UTF8::string_has_bom("\xef\xbb\xbf foobar"); // true

Parameters:

  • string $str <p>The input string.</p>

Return:

  • `bool

    true if the string has BOM at the start,
    false otherwise

`

strip_tags(string $str, string|null $allowable_tags, bool $clean_utf8): string

Strip HTML and PHP tags from a string + clean invalid UTF-8.

EXAMPLE: UTF8::strip_tags("κόσμε\xa0\xa1"); // 'κόσμε'

Parameters:

  • `string $str

    The input string.

` - `string|null $allowable_tags [optional]

You can use the optional second parameter to specify tags which should not be stripped.

HTML comments and PHP tags are also stripped. This is hardcoded and can not be changed with allowable_tags.

` - `bool $clean_utf8 [optional]

Remove non UTF-8 chars from the string.

`

Return:

  • string <p>The stripped string.</p>

strip_whitespace(string $str): string

Strip all whitespace characters. This includes tabs and newline characters, as well as multibyte whitespace such as the thin space and ideographic space.

EXAMPLE: UTF8::strip_whitespace(' Ο συγγραφέας '); // 'Οσυγγραφέας'

Parameters:

  • string $str

Return:

  • string

stripos(string $haystack, string $needle, int $offset, string $encoding, bool $clean_utf8): false|int

Find the position of the first occurrence of a substring in a string, case-insensitive.

INFO: use UTF8::stripos_in_byte() for the byte-length

EXAMPLE: UTF8::stripos('aσσb', 'ΣΣ'); // 1 (σσ == ΣΣ)

Parameters:

  • string $haystack <p>The string from which to get the position of the first occurrence of needle.</p>
  • string $needle <p>The string to find in haystack.</p>
  • int $offset [optional] <p>The position in haystack to start searching.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>

Return:

  • false|int Return the <strong>(int)</strong> numeric position of the first occurrence of needle in the haystack string,<br> or <strong>false</strong> if needle is not found

stripos_in_byte(string $haystack, string $needle, int $offset): false|int

Find the position of the first occurrence of a substring in a string, case-insensitive.

Parameters:

  • `string $haystack

    The string being checked.

` - `string $needle

The position counted from the beginning of haystack.

` - `int $offset [optional]

The search offset. If it is not specified, 0 is used.

`

Return:

  • false|int <p>The numeric position of the first occurrence of needle in the haystack string. If needle is not found, it returns false.</p>

stristr(string $haystack, string $needle, bool $before_needle, string $encoding, bool $clean_utf8): false|string

Returns all of haystack starting from and including the first occurrence of needle to the end.

EXAMPLE: $str = 'iñtërnâtiônàlizætiøn'; $search = 'NÂT';

UTF8::stristr($str, $search)); // 'nâtiônàlizætiøn' UTF8::stristr($str, $search, true)); // 'iñtër'

Parameters:

  • string $haystack <p>The input string. Must be valid UTF-8.</p>
  • string $needle <p>The string to look for. Must be valid UTF-8.</p>
  • `bool $before_needle [optional]

    If TRUE, it returns the part of the haystack before the first occurrence of the needle (excluding the needle).

` - `string $encoding [optional]

Set the charset for e.g. "mb_" function

` - `bool $clean_utf8 [optional]

Remove non UTF-8 chars from the string.

`

Return:

  • false|string <p>A sub-string,<br>or <strong>false</strong> if needle is not found.</p>

strlen(string $str, string $encoding, bool $clean_utf8): false|int

Get the string length, not the byte-length!

INFO: use UTF8::strwidth() for the char-length

EXAMPLE: UTF8::strlen("Iñtërnâtiôn\xE9àlizætiøn")); // 20

Parameters:

  • string $str <p>The string being checked for length.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>

Return:

  • `false|int

    The number (int) of characters in the string $str having character encoding $encoding. (One multi-byte character counted as +1).


Can return false, if e.g. mbstring is not installed and we process invalid chars.

`

strlen_in_byte(string $str): int

Get string length in byte.

Parameters:

  • string $str

Return:

  • int

strnatcasecmp(string $str1, string $str2, string $encoding): int

Case-insensitive string comparisons using a "natural order" algorithm.

INFO: natural order version of UTF8::strcasecmp()

EXAMPLES: UTF8::strnatcasecmp('2', '10Hello WORLD 中文空白!'); // -1 UTF8::strcasecmp('2Hello world 中文空白!', '10Hello WORLD 中文空白!'); // 1

UTF8::strnatcasecmp('10Hello world 中文空白!', '2Hello WORLD 中文空白!'); // 1 UTF8::strcasecmp('10Hello world 中文空白!', '2Hello WORLD 中文空白!'); // -1

Parameters:

  • string $str1 <p>The first string.</p>
  • string $str2 <p>The second string.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • int <strong>&lt; 0</strong> if str1 is less than str2<br> <strong>&gt; 0</strong> if str1 is greater than str2<br> <strong>0</strong> if they are equal

strnatcmp(string $str1, string $str2): int

String comparisons using a "natural order" algorithm

INFO: natural order version of UTF8::strcmp()

EXAMPLES: UTF8::strnatcmp('2Hello world 中文空白!', '10Hello WORLD 中文空白!'); // -1 UTF8::strcmp('2Hello world 中文空白!', '10Hello WORLD 中文空白!'); // 1

UTF8::strnatcmp('10Hello world 中文空白!', '2Hello WORLD 中文空白!'); // 1 UTF8::strcmp('10Hello world 中文空白!', '2Hello WORLD 中文空白!'); // -1

Parameters:

  • string $str1 <p>The first string.</p>
  • string $str2 <p>The second string.</p>

Return:

  • int <strong>&lt; 0</strong> if str1 is less than str2;<br> <strong>&gt; 0</strong> if str1 is greater than str2;<br> <strong>0</strong> if they are equal

strncasecmp(string $str1, string $str2, int $len, string $encoding): int

Case-insensitive string comparison of the first n characters.

EXAMPLE: UTF8::strcasecmp("iñtërnâtiôn\nàlizætiøn321", "iñtërnâtiôn\nàlizætiøn123", 5); // 0

Parameters:

  • string $str1 <p>The first string.</p>
  • string $str2 <p>The second string.</p>
  • int $len <p>The length of strings to be used in the comparison.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • int <strong>&lt; 0</strong> if <i>str1</i> is less than <i>str2</i>;<br> <strong>&gt; 0</strong> if <i>str1</i> is greater than <i>str2</i>;<br> <strong>0</strong> if they are equal

strncmp(string $str1, string $str2, int $len, string $encoding): int

String comparison of the first n characters.

EXAMPLE: UTF8::strncmp("Iñtërnâtiôn\nàlizætiøn321", "Iñtërnâtiôn\nàlizætiøn123", 5); // 0

Parameters:

  • string $str1 <p>The first string.</p>
  • string $str2 <p>The second string.</p>
  • int $len <p>Number of characters to use in the comparison.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • int <strong>&lt; 0</strong> if <i>str1</i> is less than <i>str2</i>;<br> <strong>&gt; 0</strong> if <i>str1</i> is greater than <i>str2</i>;<br> <strong>0</strong> if they are equal

strpbrk(string $haystack, string $char_list): false|string

Search a string for any of a set of characters.

EXAMPLE: UTF8::strpbrk('-中文空白-', '白'); // '白-'

Parameters:

  • string $haystack <p>The string where char_list is looked for.</p>
  • string $char_list <p>This parameter is case-sensitive.</p>

Return:

  • false|string <p>The string starting from the character found, or false if it is not found.</p>

strpos(string $haystack, int|string $needle, int $offset, string $encoding, bool $clean_utf8): false|int

Find the position of the first occurrence of a substring in a string.

INFO: use UTF8::strpos_in_byte() for the byte-length

EXAMPLE: UTF8::strpos('ABC-ÖÄÜ-中文空白-中文空白', '中'); // 8

Parameters:

  • string $haystack <p>The string from which to get the position of the first occurrence of needle.</p>
  • int|string $needle <p>The string to find in haystack.<br>Or a code point as int.</p>
  • int $offset [optional] <p>The search offset. If it is not specified, 0 is used.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>

Return:

  • false|int The <strong>(int)</strong> numeric position of the first occurrence of needle in the haystack string.<br> If needle is not found it returns false.

strpos_in_byte(string $haystack, string $needle, int $offset): false|int

Find the position of the first occurrence of a substring in a string.

Parameters:

  • `string $haystack

    The string being checked.

` - `string $needle

The position counted from the beginning of haystack.

` - `int $offset [optional]

The search offset. If it is not specified, 0 is used.

`

Return:

  • false|int <p>The numeric position of the first occurrence of needle in the haystack string. If needle is not found, it returns false.</p>

strrchr(string $haystack, string $needle, bool $before_needle, string $encoding, bool $clean_utf8): false|string

Find the last occurrence of a character in a string within another.

EXAMPLE: UTF8::strrchr('κόσμεκόσμε-äöü', 'κόσμε'); // 'κόσμε-äöü'

Parameters:

  • string $haystack <p>The string from which to get the last occurrence of needle.</p>
  • string $needle <p>The string to find in haystack</p>
  • `bool $before_needle [optional]

    Determines which portion of haystack this function returns. If set to true, it returns all of haystack from the beginning to the last occurrence of needle. If set to false, it returns all of haystack from the last occurrence of needle to the end,

` - `string $encoding [optional]

Set the charset for e.g. "mb_" function

` - `bool $clean_utf8 [optional]

Remove non UTF-8 chars from the string.

`

Return:

  • false|string <p>The portion of haystack or false if needle is not found.</p>

strrev(string $str, string $encoding): string

Reverses characters order in the string.

EXAMPLE: UTF8::strrev('κ-öäü'); // 'üäö-κ'

Parameters:

  • string $str <p>The input string.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string <p>The string with characters in the reverse sequence.</p>

strrichr(string $haystack, string $needle, bool $before_needle, string $encoding, bool $clean_utf8): false|string

Find the last occurrence of a character in a string within another, case-insensitive.

EXAMPLE: UTF8::strrichr('Aκόσμεκόσμε-äöü', 'aκόσμε'); // 'Aκόσμεκόσμε-äöü'

Parameters:

  • string $haystack <p>The string from which to get the last occurrence of needle.</p>
  • string $needle <p>The string to find in haystack.</p>
  • `bool $before_needle [optional]

    Determines which portion of haystack this function returns. If set to true, it returns all of haystack from the beginning to the last occurrence of needle. If set to false, it returns all of haystack from the last occurrence of needle to the end,

` - `string $encoding [optional]

Set the charset for e.g. "mb_" function

` - `bool $clean_utf8 [optional]

Remove non UTF-8 chars from the string.

`

Return:

  • false|string <p>The portion of haystack or<br>false if needle is not found.</p>

strripos(string $haystack, int|string $needle, int $offset, string $encoding, bool $clean_utf8): false|int

Find the position of the last occurrence of a substring in a string, case-insensitive.

EXAMPLE: UTF8::strripos('ABC-ÖÄÜ-中文空白-中文空白', '中'); // 13

Parameters:

  • string $haystack <p>The string to look in.</p>
  • int|string $needle <p>The string to look for.</p>
  • int $offset [optional] <p>Number of characters to ignore in the beginning or end.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>

Return:

  • false|int <p>The <strong>(int)</strong> numeric position of the last occurrence of needle in the haystack string.<br>If needle is not found, it returns false.</p>

strripos_in_byte(string $haystack, string $needle, int $offset): false|int

Finds position of last occurrence of a string within another, case-insensitive.

Parameters:

  • `string $haystack

    The string from which to get the position of the last occurrence of needle.

` - `string $needle

The string to find in haystack.

` - `int $offset [optional]

The position in haystack to start searching.

`

Return:

  • false|int <p>eturn the numeric position of the last occurrence of needle in the haystack string, or false if needle is not found.</p>

strrpos(string $haystack, int|string $needle, int $offset, string $encoding, bool $clean_utf8): false|int

Find the position of the last occurrence of a substring in a string.

EXAMPLE: UTF8::strrpos('ABC-ÖÄÜ-中文空白-中文空白', '中'); // 13

Parameters:

  • string $haystack <p>The string being checked, for the last occurrence of needle</p>
  • int|string $needle <p>The string to find in haystack.<br>Or a code point as int.</p>
  • `int $offset [optional]

    May be specified to begin searching an arbitrary number of characters into the string. Negative values will stop searching at an arbitrary point prior to the end of the string.

` - `string $encoding [optional]

Set the charset.

` - `bool $clean_utf8 [optional]

Remove non UTF-8 chars from the string.

`

Return:

  • false|int <p>The <strong>(int)</strong> numeric position of the last occurrence of needle in the haystack string.<br>If needle is not found, it returns false.</p>

strrpos_in_byte(string $haystack, string $needle, int $offset): false|int

Find the position of the last occurrence of a substring in a string.

Parameters:

  • `string $haystack

    The string being checked, for the last occurrence of needle.

` - `string $needle

The string to find in haystack.

` - `int $offset [optional]

May be specified to begin searching an arbitrary number of characters into the string. Negative values will stop searching at an arbitrary point prior to the end of the string.

`

Return:

  • false|int <p>The numeric position of the last occurrence of needle in the haystack string. If needle is not found, it returns false.</p>

strspn(string $str, string $mask, int $offset, int|null $length, string $encoding): false|int

Finds the length of the initial segment of a string consisting entirely of characters contained within a given mask.

EXAMPLE: UTF8::strspn('iñtërnâtiônàlizætiøn', 'itñ'); // '3'

Parameters:

  • string $str <p>The input string.</p>
  • string $mask <p>The mask of chars</p>
  • int $offset [optional]
  • int|null $length [optional]
  • string $encoding [optional] <p>Set the charset.</p>

Return:

  • false|int

strstr(string $haystack, string $needle, bool $before_needle, string $encoding, bool $clean_utf8): false|string

Returns part of haystack string from the first occurrence of needle to the end of haystack.

EXAMPLE: $str = 'iñtërnâtiônàlizætiøn'; $search = 'nât';

UTF8::strstr($str, $search)); // 'nâtiônàlizætiøn' UTF8::strstr($str, $search, true)); // 'iñtër'

Parameters:

  • string $haystack <p>The input string. Must be valid UTF-8.</p>
  • string $needle <p>The string to look for. Must be valid UTF-8.</p>
  • `bool $before_needle [optional]

    If TRUE, strstr() returns the part of the haystack before the first occurrence of the needle (excluding the needle).

` - `string $encoding [optional]

Set the charset for e.g. "mb_" function

` - `bool $clean_utf8 [optional]

Remove non UTF-8 chars from the string.

`

Return:

  • false|string <p>A sub-string,<br>or <strong>false</strong> if needle is not found.</p>

strstr_in_byte(string $haystack, string $needle, bool $before_needle): false|string

Finds first occurrence of a string within another.

Parameters:

  • `string $haystack

    The string from which to get the first occurrence of needle.

` - `string $needle

The string to find in haystack.

` - `bool $before_needle [optional]

Determines which portion of haystack this function returns. If set to true, it returns all of haystack from the beginning to the first occurrence of needle. If set to false, it returns all of haystack from the first occurrence of needle to the end,

`

Return:

  • false|string <p>The portion of haystack, or false if needle is not found.</p>

strtocasefold(string $str, bool $full, bool $clean_utf8, string $encoding, string|null $lang, bool $lower): string

Unicode transformation for case-less matching.

EXAMPLE: UTF8::strtocasefold('ǰ◌̱'); // 'ǰ◌̱'

Parameters:

  • string $str <p>The input string.</p>
  • `bool $full [optional]

    true, replace full case folding chars (default)
    false, use only limited static array [UTF8::$COMMON_CASE_FOLD]

` - `bool $clean_utf8 [optional]

Remove non UTF-8 chars from the string.

` - `string $encoding [optional]

Set the charset.

` - `string|null $lang [optional]

Set the language for special cases: az, el, lt, tr

` - `bool $lower [optional]

Use lowercase string, otherwise use uppercase string. PS: uppercase is for some languages better ...

`

Return:

  • string

strtolower(string $str, string $encoding, bool $clean_utf8, string|null $lang, bool $try_to_keep_the_string_length): string

Make a string lowercase.

EXAMPLE: UTF8::strtolower('DÉJÀ Σσς Iıİi'); // 'déjà σσς iıii'

Parameters:

  • string $str <p>The string being lowercased.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>
  • string|null $lang [optional] <p>Set the language for special cases: az, el, lt, tr</p>
  • bool $try_to_keep_the_string_length [optional] <p>true === try to keep the string length: e.g. ẞ -> ß</p>

Return:

  • string <p>String with all alphabetic characters converted to lowercase.</p>

strtoupper(string $str, string $encoding, bool $clean_utf8, string|null $lang, bool $try_to_keep_the_string_length): string

Make a string uppercase.

EXAMPLE: UTF8::strtoupper('Déjà Σσς Iıİi'); // 'DÉJÀ ΣΣΣ IIİI'

Parameters:

  • string $str <p>The string being uppercased.</p>
  • string $encoding [optional] <p>Set the charset.</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>
  • string|null $lang [optional] <p>Set the language for special cases: az, el, lt, tr</p>
  • bool $try_to_keep_the_string_length [optional] <p>true === try to keep the string length: e.g. ẞ -> ß</p>

Return:

  • string <p>String with all alphabetic characters converted to uppercase.</p>

strtr(string $str, string|string[] $from, string|string[] $to): string

Translate characters or replace sub-strings.

EXAMPLE: $array = [ 'Hello' => '○●◎', '中文空白' => 'earth', ]; UTF8::strtr('Hello 中文空白', $array); // '○●◎ earth'

Parameters:

  • string $str <p>The string being translated.</p>
  • string|string[] $from <p>The string replacing from.</p>
  • string|string[] $to [optional] <p>The string being translated to to.</p>

Return:

  • string <p>This function returns a copy of str, translating all occurrences of each character in "from" to the corresponding character in "to".</p>

strwidth(string $str, string $encoding, bool $clean_utf8): int

Return the width of a string.

INFO: use UTF8::strlen() for the byte-length

EXAMPLE: UTF8::strwidth("Iñtërnâtiôn\xE9àlizætiøn")); // 21

Parameters:

  • string $str <p>The input string.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>

Return:

  • int

substr(string $str, int $offset, int|null $length, string $encoding, bool $clean_utf8): false|string

Get part of a string.

EXAMPLE: UTF8::substr('中文空白', 1, 2); // '文空'

Parameters:

  • string $str <p>The string being checked.</p>
  • int $offset <p>The first position used in str.</p>
  • int|null $length [optional] <p>The maximum length of the returned string.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>

Return:

  • false|string The portion of <i>str</i> specified by the <i>offset</i> and <i>length</i> parameters.</p><p>If <i>str</i> is shorter than <i>offset</i> characters long, <b>FALSE</b> will be returned.

substr_compare(string $str1, string $str2, int $offset, int|null $length, bool $case_insensitivity, string $encoding): int

Binary-safe comparison of two strings from an offset, up to a length of characters.

EXAMPLE: UTF8::substr_compare("○●◎\r", '●◎', 0, 2); // -1 UTF8::substr_compare("○●◎\r", '◎●', 1, 2); // 1 UTF8::substr_compare("○●◎\r", '●◎', 1, 2); // 0

Parameters:

  • string $str1 <p>The main string being compared.</p>
  • string $str2 <p>The secondary string being compared.</p>
  • int $offset [optional] <p>The start position for the comparison. If negative, it starts counting from the end of the string.</p>
  • int|null $length [optional] <p>The length of the comparison. The default value is the largest of the length of the str compared to the length of main_str less the offset.</p>
  • bool $case_insensitivity [optional] <p>If case_insensitivity is TRUE, comparison is case insensitive.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • int <strong>&lt; 0</strong> if str1 is less than str2;<br> <strong>&gt; 0</strong> if str1 is greater than str2,<br> <strong>0</strong> if they are equal

substr_count(string $haystack, string $needle, int $offset, int|null $length, string $encoding, bool $clean_utf8): false|int

Count the number of substring occurrences.

EXAMPLE: UTF8::substr_count('中文空白', '文空', 1, 2); // 1

Parameters:

  • string $haystack <p>The string to search in.</p>
  • string $needle <p>The substring to search for.</p>
  • int $offset [optional] <p>The offset where to start counting.</p>
  • `int|null $length [optional]

    The maximum length after the specified offset to search for the substring. It outputs a warning if the offset plus the length is greater than the haystack length.

` - `string $encoding [optional]

Set the charset for e.g. "mb_" function

` - `bool $clean_utf8 [optional]

Remove non UTF-8 chars from the string.

`

Return:

  • false|int <p>This functions returns an integer or false if there isn't a string.</p>

substr_count_in_byte(string $haystack, string $needle, int $offset, int|null $length): false|int

Count the number of substring occurrences.

Parameters:

  • `string $haystack

    The string being checked.

` - `string $needle

The string being found.

` - `int $offset [optional]

The offset where to start counting

` - `int|null $length [optional]

The maximum length after the specified offset to search for the substring. It outputs a warning if the offset plus the length is greater than the haystack length.

`

Return:

  • false|int <p>The number of times the needle substring occurs in the haystack string.</p>

substr_count_simple(string $str, string $substring, bool $case_sensitive, string $encoding): int

Returns the number of occurrences of $substring in the given string.

By default, the comparison is case-sensitive, but can be made insensitive by setting $case_sensitive to false.

Parameters:

  • string $str <p>The input string.</p>
  • string $substring <p>The substring to search for.</p>
  • bool $case_sensitive [optional] <p>Whether or not to enforce case-sensitivity. Default: true</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • int

substr_ileft(string $haystack, string $needle): string

Removes a prefix ($needle) from the beginning of the string ($haystack), case-insensitive.

EXMAPLE: UTF8::substr_ileft('ΚόσμεMiddleEnd', 'Κόσμε'); // 'MiddleEnd' UTF8::substr_ileft('ΚόσμεMiddleEnd', 'κόσμε'); // 'MiddleEnd'

Parameters:

  • string $haystack <p>The string to search in.</p>
  • string $needle <p>The substring to search for.</p>

Return:

  • string <p>Return the sub-string.</p>

substr_in_byte(string $str, int $offset, int|null $length): false|string

Get part of a string process in bytes.

Parameters:

  • string $str <p>The string being checked.</p>
  • int $offset <p>The first position used in str.</p>
  • int|null $length [optional] <p>The maximum length of the returned string.</p>

Return:

  • false|string The portion of <i>str</i> specified by the <i>offset</i> and <i>length</i> parameters.</p><p>If <i>str</i> is shorter than <i>offset</i> characters long, <b>FALSE</b> will be returned.

substr_iright(string $haystack, string $needle): string

Removes a suffix ($needle) from the end of the string ($haystack), case-insensitive.

EXAMPLE: UTF8::substr_iright('BeginMiddleΚόσμε', 'Κόσμε'); // 'BeginMiddle' UTF8::substr_iright('BeginMiddleΚόσμε', 'κόσμε'); // 'BeginMiddle'

Parameters:

  • string $haystack <p>The string to search in.</p>
  • string $needle <p>The substring to search for.</p>

Return:

  • string <p>Return the sub-string.<p>

substr_left(string $haystack, string $needle): string

Removes a prefix ($needle) from the beginning of the string ($haystack).

EXAMPLE: UTF8::substr_left('ΚόσμεMiddleEnd', 'Κόσμε'); // 'MiddleEnd' UTF8::substr_left('ΚόσμεMiddleEnd', 'κόσμε'); // 'ΚόσμεMiddleEnd'

Parameters:

  • string $haystack <p>The string to search in.</p>
  • string $needle <p>The substring to search for.</p>

Return:

  • string <p>Return the sub-string.</p>

substr_replace(string|string[] $str, string|string[] $replacement, int|int[] $offset, int|int[]|null $length, string $encoding): string|string[]

Replace text within a portion of a string.

EXAMPLE: UTF8::substr_replace(array('Iñtërnâtiônàlizætiøn', 'foo'), 'æ', 1); // array('Iæñtërnâtiônàlizætiøn', 'fæoo')

source: https://gist.github.com/stemar/8287074

Parameters:

  • string|string[] $str <p>The input string or an array of stings.</p>
  • string|string[] $replacement <p>The replacement string or an array of stings.</p>
  • `int|int[] $offset

    If start is positive, the replacing will begin at the start'th offset into string.

    If start is negative, the replacing will begin at the start'th character from the end of string.

` - `int|int[]|null $length [optional]

If given and is positive, it represents the length of the portion of string which is to be replaced. If it is negative, it represents the number of characters from the end of string at which to stop replacing. If it is not given, then it will default to strlen( string ); i.e. end the replacing at the end of string. Of course, if length is zero then this function will have the effect of inserting replacement into string at the given start offset.

` - `string $encoding [optional]

Set the charset for e.g. "mb_" function

`

Return:

  • string|string[] <p>The result string is returned. If string is an array then array is returned.</p>

substr_right(string $haystack, string $needle, string $encoding): string

Removes a suffix ($needle) from the end of the string ($haystack).

EXAMPLE: UTF8::substr_right('BeginMiddleΚόσμε', 'Κόσμε'); // 'BeginMiddle' UTF8::substr_right('BeginMiddleΚόσμε', 'κόσμε'); // 'BeginMiddleΚόσμε'

Parameters:

  • string $haystack <p>The string to search in.</p>
  • string $needle <p>The substring to search for.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>

Return:

  • string <p>Return the sub-string.</p>

swapCase(string $str, string $encoding, bool $clean_utf8): string

Returns a case swapped version of the string.

EXAMPLE: UTF8::swapCase('déJÀ σσς iıII'); // 'DÉjà ΣΣΣ IIii'

Parameters:

  • string $str <p>The input string.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>

Return:

  • string <p>Each character's case swapped.</p>

symfony_polyfill_used(): bool

Checks whether symfony-polyfills are used.

Parameters: nothing

Return:

  • bool <p><strong>true</strong> if in use, <strong>false</strong> otherwise</p>

tabs_to_spaces(string $str, int $tab_length): string

Parameters:

  • string $str
  • int $tab_length

Return:

  • string

titlecase(string $str, string $encoding, bool $clean_utf8, string|null $lang, bool $try_to_keep_the_string_length): string

Converts the first character of each word in the string to uppercase and all other chars to lowercase.

Parameters:

  • string $str <p>The input string.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>
  • string|null $lang [optional] <p>Set the language for special cases: az, el, lt, tr</p>
  • bool $try_to_keep_the_string_length [optional] <p>true === try to keep the string length: e.g. ẞ -> ß</p>

Return:

  • string <p>A string with all characters of $str being title-cased.</p>

to_ascii(string $str, string $unknown, bool $strict): string

Convert a string into ASCII.

EXAMPLE: UTF8::to_ascii('déjà σσς iıii'); // 'deja sss iiii'

Parameters:

  • string $str <p>The input string.</p>
  • string $unknown [optional] <p>Character use if character unknown. (default is ?)</p>
  • bool $strict [optional] <p>Use "transliterator_transliterate()" from PHP-Intl | WARNING: bad performance</p>

Return:

  • string

to_boolean(bool|float|int|string $str): bool

Parameters:

  • bool|float|int|string $str

Return:

  • bool

to_filename(string $str, bool $use_transliterate, string $fallback_char): string

Convert given string to safe filename (and keep string case).

Parameters:

  • string $str
  • bool $use_transliterate No transliteration, conversion etc. is done by default - unsafe characters are simply replaced with hyphen.
  • string $fallback_char

Return:

  • string

to_int(string $str): int|null

Returns the given string as an integer, or null if the string isn't numeric.

Parameters:

  • string $str

Return:

  • int|null <p>null if the string isn't numeric</p>

to_iso8859(string|string[] $str): string|string[]

Convert a string into "ISO-8859"-encoding (Latin-1).

EXAMPLE: UTF8::to_utf8(UTF8::to_iso8859(' -ABC-中文空白- ')); // ' -ABC-????- '

Parameters:

  • string|string[] $str

Return:

  • string|string[]

to_string(float|int|object|string|null $input): string|null

Returns the given input as string, or null if the input isn't int|float|string and do not implement the "__toString()" method.

Parameters:

  • float|int|object|string|null $input

Return:

  • string|null <p>null if the input isn't int|float|string and has no "__toString()" method</p>

to_utf8(string|string[] $str, bool $decode_html_entity_to_utf8): string|string[]

This function leaves UTF-8 characters alone, while converting almost all non-UTF8 to UTF8.

  • It decode UTF-8 codepoints and Unicode escape sequences.
  • It assumes that the encoding of the original string is either WINDOWS-1252 or ISO-8859.
  • WARNING: It does not remove invalid UTF-8 characters, so you maybe need to use "UTF8::clean()" for this case.

EXAMPLE: UTF8::to_utf8(["\u0063\u0061\u0074"]); // array('cat')

Parameters:

  • TToUtf8 $str <p>Any string or array of strings.</p>
  • bool $decode_html_entity_to_utf8 <p>Set to true, if you need to decode html-entities.</p>

Return:

  • string|string[] <p>The UTF-8 encoded string</p>

to_utf8_string(string $str, bool $decode_html_entity_to_utf8): string

This function leaves UTF-8 characters alone, while converting almost all non-UTF8 to UTF8.

  • It decode UTF-8 codepoints and Unicode escape sequences.
  • It assumes that the encoding of the original string is either WINDOWS-1252 or ISO-8859.
  • WARNING: It does not remove invalid UTF-8 characters, so you maybe need to use "UTF8::clean()" for this case.

EXAMPLE: UTF8::to_utf8_string("\u0063\u0061\u0074"); // 'cat'

Parameters:

  • string $str <p>Any string.</p>
  • bool $decode_html_entity_to_utf8 <p>Set to true, if you need to decode html-entities.</p>

Return:

  • string <p>The UTF-8 encoded string</p>

trim(string $str, string|null $chars): string

Strip whitespace or other characters from the beginning and end of a UTF-8 string.

INFO: This is slower then "trim()"

We can only use the original-function, if we use <= 7-Bit in the string / chars but the check for ASCII (7-Bit) cost more time, then we can safe here.

EXAMPLE: UTF8::trim(' -ABC-中文空白- '); // '-ABC-中文空白-'

Parameters:

  • string $str <p>The string to be trimmed</p>
  • string|null $chars [optional] <p>Optional characters to be stripped</p>

Return:

  • string <p>The trimmed string.</p>

ucfirst(string $str, string $encoding, bool $clean_utf8, string|null $lang, bool $try_to_keep_the_string_length): string

Makes string's first char uppercase.

EXAMPLE: UTF8::ucfirst('ñtërnâtiônàlizætiøn foo'); // 'Ñtërnâtiônàlizætiøn foo'

Parameters:

  • string $str <p>The input string.</p>
  • string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>
  • string|null $lang [optional] <p>Set the language for special cases: az, el, lt, tr</p>
  • bool $try_to_keep_the_string_length [optional] <p>true === try to keep the string length: e.g. ẞ -> ß</p>

Return:

  • string <p>The resulting string with with char uppercase.</p>

ucwords(string $str, string[] $exceptions, string $char_list, string $encoding, bool $clean_utf8): string

Uppercase for all words in the string.

EXAMPLE: UTF8::ucwords('iñt ërn âTi ônà liz æti øn'); // 'Iñt Ërn ÂTi Ônà Liz Æti Øn'

Parameters:

  • string $str <p>The input string.</p>
  • string[] $exceptions [optional] <p>Exclusion for some words.</p>
  • string $char_list [optional] <p>Additional chars that contains to words and do not start a new word.</p>
  • string $encoding [optional] <p>Set the charset.</p>
  • bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>

Return:

  • string

urldecode(string $str, bool $multi_decode): string

Multi decode HTML entity + fix urlencoded-win1252-chars.

EXAMPLE: UTF8::urldecode('tes%20öäü%20\u00edtest+test'); // 'tes öäü ítest test'

e.g: 'test+test' => 'test test' 'Düsseldorf' => 'Düsseldorf' 'D%FCsseldorf' => 'Düsseldorf' 'Düsseldorf' => 'Düsseldorf' 'D%26%23xFC%3Bsseldorf' => 'Düsseldorf' 'Düsseldorf' => 'Düsseldorf' 'D%C3%BCsseldorf' => 'Düsseldorf' 'D%C3%83%C2%BCsseldorf' => 'Düsseldorf' 'D%25C3%2583%25C2%25BCsseldorf' => 'Düsseldorf'

Parameters:

  • string $str <p>The input string.</p>
  • bool $multi_decode <p>Decode as often as possible.</p>

Return:

  • string

utf8_decode(string $str, bool $keep_utf8_chars): string

Decodes a UTF-8 string to ISO-8859-1.

EXAMPLE: UTF8::encode('UTF-8', UTF8::utf8_decode('-ABC-中文空白-')); // '-ABC-????-'

Parameters:

  • string $str <p>The input string.</p>
  • bool $keep_utf8_chars

Return:

  • string

utf8_encode(string $str): string

Encodes an ISO-8859-1 string to UTF-8.

EXAMPLE: UTF8::utf8_decode(UTF8::utf8_encode('-ABC-中文空白-')); // '-ABC-中文空白-'

Parameters:

  • string $str <p>The input string.</p>

Return:

  • string

whitespace_table(): string[]

Returns an array with all utf8 whitespace characters.

Parameters: nothing

Return:

  • string[] An array with all known whitespace characters as values and the type of whitespace as keys as defined in above URL

words_limit(string $str, int $limit, string $str_add_on): string

Limit the number of words in a string.

EXAMPLE: UTF8::words_limit('fòô bàř fòô', 2, ''); // 'fòô bàř'

Parameters:

  • string $str <p>The input string.</p>
  • int $limit <p>The limit of words as integer.</p>
  • string $str_add_on <p>Replacement for the striped string.</p>

Return:

  • string

wordwrap(string $str, int $width, string $break, bool $cut): string

Wraps a string to a given number of characters

EXAMPLE: UTF8::wordwrap('Iñtërnâtiônàlizætiøn', 2, '
', true)); // 'Iñ

rn
ât


li

ti
øn'

Parameters:

  • string $str <p>The input string.</p>
  • int $width [optional] <p>The column width.</p>
  • string $break [optional] <p>The line is broken using the optional break parameter.</p>
  • `bool $cut [optional]

    If the cut is set to true, the string is always wrapped at or before the specified width. So if you have a word that is larger than the given width, it is broken apart.

`

Return:

  • string <p>The given string wrapped at the specified column.</p>

wordwrap_per_line(string $str, int $width, string $break, bool $cut, bool $add_final_break, string|null $delimiter): string

Line-Wrap the string after $limit, but split the string by "$delimiter" before .

.. ... so that we wrap the per line.

Parameters:

  • string $str <p>The input string.</p>
  • int $width [optional] <p>The column width.</p>
  • string $break [optional] <p>The line is broken using the optional break parameter.</p>
  • `bool $cut [optional]

    If the cut is set to true, the string is always wrapped at or before the specified width. So if you have a word that is larger than the given width, it is broken apart.

` - `bool $add_final_break [optional]

If this flag is true, then the method will add a $break at the end of the result string.

` - `string|null $delimiter [optional]

You can change the default behavior, where we split the string by newline.

`

Return:

  • string

ws(): string[]

Returns an array of Unicode White Space characters.

Parameters: nothing

Return:

  • string[] <p>An array with numeric code point as key and White Space Character as value.</p>

Unit Test

  1. Composer is a prerequisite for running the tests.
composer install
  1. The tests can be executed by running this command from the root directory:
./vendor/bin/phpunit

Support

For support and donations please visit GitHub | Issues | PayPal | Patreon.

For status updates and release announcements please visit Releases | Twitter | Patreon.

For professional support please contact me.

Thanks

  • Thanks to GitHub (Microsoft) for hosting the code and a good infrastructure including Issues-Management, etc.
  • Thanks to IntelliJ as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
  • Thanks to Travis CI for being the most awesome, easiest continuous integration tool out there!
  • Thanks to StyleCI for the simple but powerful code style check.
  • Thanks to PHPStan && Psalm for really great Static analysis tools and for discovering bugs in the code!

License and Copyright

"Portable UTF8" is free software; you can redistribute it and/or modify it under the terms of the (at your option):

Unicode handling requires tedious work to be implemented and maintained on the long run. As such, contributions such as unit tests, bug reports, comments or patches licensed under both licenses are really welcomed.

FOSSA Status

Comments
  • mb_strlen for multibyte check

    mb_strlen for multibyte check

    Fixes #

    Proposed Changes

    • use mb_strlen with specific encoding '8bit' to avoid problems when using mbstring.func_overload in php.ini

    This change is Reviewable

    opened by eelco2k 13
  • [PHP 8.2] Fix `${var}` string interpolation deprecation

    [PHP 8.2] Fix `${var}` string interpolation deprecation

    opened by Ayesh 7
  • Not all features in the readme

    Not all features in the readme

    Hello!

    Right now I am using method - str_truncate_safe but coudn`t find it in the readme file.

    It will be nice to see all available methods in the readme or some other documentation.

    documentation 
    opened by olegatro 7
  • How to fix

    How to fix "Maximum execution" problem

    Hi, there~

    My environment is PHP 5.6, So I make some changes to let the code fit the runtime. I found the CPU capacity of my server is over 90% last week, And I captured the error:

    PHP Fatal error: Maximum execution time of 60 seconds exceeded in /UTF8.php on line xxx

    The maybe-wrong code is to_utf8 function:

    public static function to_utf8($str,  $decodeHtmlEntityToUtf8 = false){
      if (\is_array($str) === true) {
        foreach ($str as $k => $v) {
          $str[$k] = self::to_utf8($v, $decodeHtmlEntityToUtf8);
        }
    
        return $str;
      }
    
      $str = (string)$str;
      if ('' === $str) {
        return $str;
      }
    
      if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
        self::checkForSupport();
      }
    
      $max = self::strlen_in_byte($str);
      $buf = '';
    
      /** @noinspection ForeachInvariantsInspection */
      for ($i = 0; $i < $max; $i++) {
        $c1 = $str[$i];
    
        if ($c1 >= "\xC0") { // should be converted to UTF8, if it's not UTF8 already
    
          if ($c1 <= "\xDF") { // looks like 2 bytes UTF8
    
            $c2 = $i + 1 >= $max ? "\x00" : $str[$i + 1];
    
            if ($c2 >= "\x80" && $c2 <= "\xBF") { // yeah, almost sure it's UTF8 already
              $buf .= $c1 . $c2;
              $i++;
            } else { // not valid UTF8 - convert it
              $buf .= self::to_utf8_convert_helper($c1);
            }
    
          } elseif ($c1 >= "\xE0" && $c1 <= "\xEF") { // looks like 3 bytes UTF8
    
            $c2 = $i + 1 >= $max ? "\x00" : $str[$i + 1];
            $c3 = $i + 2 >= $max ? "\x00" : $str[$i + 2];
    
            if ($c2 >= "\x80" && $c2 <= "\xBF" && $c3 >= "\x80" && $c3 <= "\xBF") { // yeah, almost sure it's UTF8 already
              $buf .= $c1 . $c2 . $c3;
              $i += 2;
            } else { // not valid UTF8 - convert it
              $buf .= self::to_utf8_convert_helper($c1);
            }
    
          } elseif ($c1 >= "\xF0" && $c1 <= "\xF7") { // looks like 4 bytes UTF8
    
            $c2 = $i + 1 >= $max ? "\x00" : $str[$i + 1];
            $c3 = $i + 2 >= $max ? "\x00" : $str[$i + 2];
            $c4 = $i + 3 >= $max ? "\x00" : $str[$i + 3];
    
            if ($c2 >= "\x80" && $c2 <= "\xBF" && $c3 >= "\x80" && $c3 <= "\xBF" && $c4 >= "\x80" && $c4 <= "\xBF") { // yeah, almost sure it's UTF8 already
              $buf .= $c1 . $c2 . $c3 . $c4;
              $i += 3;
            } else { // not valid UTF8 - convert it
              $buf .= self::to_utf8_convert_helper($c1);
            }
    
          } else { // doesn't look like UTF8, but should be converted
            $buf .= self::to_utf8_convert_helper($c1);
          }
    
        } elseif (($c1 & "\xC0") === "\x80") { // needs conversion
    
          $buf .= self::to_utf8_convert_helper($c1);
    
        } else { // it doesn't need conversion
          $buf .= $c1;
        }
      }
    
      // decode unicode escape sequences
      $buf = \preg_replace_callback(
          '/\\\\u([0-9a-f]{4})/i',
          function ($match) {
            // always fallback via symfony polyfill
            return \mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
          },
          $buf
      );
    
      // decode UTF-8 codepoints
      if ($decodeHtmlEntityToUtf8 === true) {
        $buf = self::html_entity_decode($buf);
      }
    
      return $buf;
    }
    

    I found that the latest version of 'UTF8.PHP' has different to_utf8 function, I wonder if I need to update to the latest version? (Have the latest version fixed this problem?)

    Thanks in advance!

    wait for response 
    opened by kazaff 7
  • Add UTF8::levenshtein()

    Add UTF8::levenshtein()

    Proposed Changes

    • Add UTF8::levenshtein()

    Thanks for very useful and well-tested library, how about multibyte \levenshtein() wrapper?


    This change is Reviewable

    opened by NewEXE 6
  • Do not use for PHP 5.6

    Do not use for PHP 5.6

    Hi @voku ,

    I using PHP version 5.6 then class Bootup error function random_bytes() (line 164). how to fix problem

    random_bytes() => PHP7

    I use function openssl_random_pseudo_bytes() replace is stability ?

    thanks

    opened by hoangnamitc 6
  • Update shivammathur/setup-php action to v2.20.1

    Update shivammathur/setup-php action to v2.20.1

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | shivammathur/setup-php | action | minor | 2.16.0 -> 2.20.1 |


    Release Notes

    shivammathur/setup-php

    v2.20.1

    Compare Source

    Support Ukraine

    #StandWithUkraine



    Follow for updates

    setup-php reddit setup-php twitter setup-php status

    v2.20.0

    Compare Source

    Support Ukraine

    #StandWithUkraine


    • Improved support for event extension on Linux and macOS for PHP 5.4 and above. #​604

    • Fixed support for composer plugins in tools input. Since composer 2.2, the plugins are required to be marked as allowed in the composer config. This will now be done by default. #​611

    • Added support to show code coverage driver's (Xdebug/PCOV) version in the logs when setup using the coverage input. #​610

    • Fixed a bug where PHP was not added to PATH during the action run on self-hosted Windows environments. #​609

    • Fixed a bug where the tool cache path was not set on self-hosted environments. #​606

    • Updated Node.js dependencies.


    Thanks! @​jrfnl, @​dino182 and @​markseuffert for the contributions 🚀

    Follow for updates

    setup-php reddit setup-php twitter setup-php status

    v2.19.1

    Compare Source

    Support Ukraine

    #StandWithUkraine


    • Fixed support for deployer.

    • Updated Node.js dependencies.


    Follow for updates

    setup-php reddit setup-php twitter setup-php status

    v2.19.0

    Compare Source

    Support Ukraine

    #StandWithUkraine


    • Added support for ubuntu-22.04 runner. Docs

    • Added support for Couchbase extension 4.x for PHP 7.4 and above. Also added support to specify the extension version you need. https://github.com/shivammathur/setup-php/issues/593

      Note: Please use the extensions cache if using the latest Couchbase version on Linux as it can take 10+ minutes to build along with its library.

      To install the latest version of couchbase extension

      - name: Setup PHP
        uses: shivammathur@setup-php@v2
        with:
          php-version: '8.1'
          extensions: couchbase
      

      To install a specific version - suffix couchbase with exact version you want in the extensions input.

      - name: Setup PHP
        uses: shivammathur@setup-php@v2
        with:
          php-version: '7.4'
          extensions: couchbase-2.6.2
      
    • Improved fallback support upon cache failure in composer setup. This fixes an error when the latest composer version was installed on older PHP versions when fetching composer from shivammathur/composer-cache failed.

    • Bumped Node.js version required to 16.x. Also bumped build target version to ES2021.

    • Removed support for Debian 9 and Ubuntu 21.04 for self-hosted runners. Docs

    • Fixed tools setup with older composer versions which do not create composer.json if missing in the directory.

    • Fixed support for extensions on macOS where the extension package name might conflict with package names in homebrew-core repo. This fixes support for redis extension on macOS on PHP 7.0.

    • Fixed enabling cached extensions which depend on other extensions on PHP 7.1 and lower.

    • Fixed setting default INI values so that it is possible to override those using php -c. https://github.com/shivammathur/setup-php/issues/595

    • Fixed PECL support for PHP 5.3, this was broken in previous release while adding support for specifying configure options, as that is only supported on PHP 5.4 and above.

    • Fixed identifying the latest protoc release.

    • Removed unnecessary fs dependency.

    • Added dependabot config to update older actions in workflows. https://github.com/shivammathur/setup-php/pull/597

    • Added permissions for GITHUB_TOKEN in workflows. https://github.com/shivammathur/setup-php/pull/596

    • Updated Node.js dependencies.


    Thanks! @​naveensrinivasan for the contributions 🚀

    Follow for updates

    setup-php reddit setup-php twitter setup-php status

    v2.18.1

    Compare Source

    Support Ukraine

    #StandWithUkraine


    - name: Setup PHP with intl
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.1'
        extensions: intl-71.1
    
    • Added support for macOS Monterey (macos-12) GitHub hosted environment.

    • Added support for mcrypt extension using shivammathur/extensions tap on macOS.

    • Fixed patching brew for overwriting existing linked libraries.

    • Fixed identifying the latest protoc release.

    • Updated Node.js dependencies.


    Thanks! @​jderusse for the contributions 🚀

    Follow for updates

    setup-php reddit setup-php twitter setup-php status

    v2.18.0

    Compare Source

    Support Ukraine

    #StandWithUkraine


    • Added support for installing libraries and custom configure options for PECL extensions. #​575. Docs.

    • Added support for blackfire extension on PHP 8.1 on Windows.

    • Improved support for http extension on Windows and self-hosted environments.

    • Fixed installing php-dev package on self-hosted environments when missing. #​569

    • Fixed linking pecl ini file on self-hosted environments. #​569

    • Fixed copying extensions when installed using brew from its Cellar to extension directory on macOS.

    • Fixed generating extension dependency map.

    • Fixed a bug in log functions on Linux and macOS by using local variables.

    • Improved switching versions on Linux. #​572

    • Improved enabling default extensions by reducing PHP calls.

    • Bumped actions/checkout, actions/upload-artifact, actions/download-artifact and actions/cache version in examples and workflows to v3. #​571, #​577

    • Added PECL customization guide to README.

    • Updated Node.js dependencies.


    Thanks! @​jrfnl for the contributions 🚀

    Follow for updates

    setup-php reddit setup-php twitter setup-php status

    v2.17.1

    Compare Source

    This release is possible because of our sponsors ❤️.

    Help setup-php reach its sponsorship goals.

    Sponsor shivammathur


    • Added support for OpenSSL config on Windows. #​564 Now setup-php will set the environment variable OPENSSL_CONF pointing to a valid openssl.cnf file on Windows.

    • Added GitHub releases fallback URL for phing.

    • Updated version of sqlsrv and pdo_sqlsrv extensions to 5.10.0 for PHP 7.4 and above.

    • Fixed logs for symfony-cli on failure. #​568

    • Fixed setting an environment variable on Windows in self-hosted environments.

    • Fixed a bug in adding a directory to PATH. #​562

    • Fixed a minor UUOC shellcheck warning in add_tools.sh.

    • Updated Node.js dependencies.


    Thanks! @​mlocati for adding Set-OpenSSLConf 🚀

    Follow for updates

    setup-php reddit setup-php twitter setup-php status

    v2.17.0

    Compare Source

    This release is possible because of our sponsors ❤️.

    Help setup-php reach its sponsorship goals.

    Sponsor shivammathur


    • Added ini-file input to specify the base php.ini file. Accepts production, development or none. Docs (#​450, #​469)

    By default the production php.ini is used, you can change it to the development one, or remove it using none.

    - name: Setup PHP
      with:
        php-version: '8.1'
        ini-file: development
    
    - name: Setup PHP
      with:
        php-version: '8.1'
        tools: symfony-cli
    
    - name: Setup PHP
      with:
        php-version: '8.1'
        tools: churn
    
    • Added support for blackfire extension on PHP 8.1.
    - name: Setup PHP
      with:
        php-version: '8.1'
        extensions: blackfire
    
    • Tools pecl, phpize and php-config are now installed by default on Linux. Specifying these in tools input is no longer required.

    • The environment variable COMPOSER_NO_INTERACTION is now set to 1 by default, so using --no-interaction in composer commands is not required. (#​547)

    • The environment is now considered self-hosted unless the GitHub hosted environment is detected. This should prevent broken PHP installs in self-hosted environments when the runner environment variable is not specified. (#​554)

    • Added support to enable disabled extensions when required by tools. For this extensions are now processed before tools.

    • Added support to enable xml extension before installing other extensions using pecl. (#​553)

    • Speed improvements

      • Reduced the initial I/O in script creation.
      • Reduced the number of PHP calls and it now uses php-config instead.
      • Reduced number of brew calls on macOS setup.
      • Windows builds for all PHP versions are now fetched from shivammathur/php-builder-windows releases as a faster cache with windows.php.net as a fallback.
      • SSL libraries for PHP 5.3 to 5.5 on Windows are now fetched in parallel.
      • PHP builds for PHP 5.3 to 5.5 should now use cached macports builds from shivammathur/php5-darwin.
    • Added support for installing tools using composer in different scopes. This allows installing two tools with different versions of a common dependency. (#​549)

    • Added support to fail immediately when composer setup fails. (#​548)

    • Added support to parse PECL extension versions when wrongly hyphenated. (#​536)

    • Added support for composer phars from shivammathur/composer-cache with PHP version as now different PHP versions can have different composer versions for a release type.

    • Added setup-php.com as a fallback in addition to jsdeliver.com for script sources.

    • Fixed support for fallback sources for tools in Windows.

    • Fixed potential exponential backtracking in regex to parse extension input when installing extensions from a git repository.

    • Fixed adding sudo to self-hosted Linux environments. (#​555)

    • Fixed enabling disabled extensions with other extensions as dependencies. For example pecl_http, redis, etc.

    • Fixed a bug where the ini file used for enabling extensions by pecl in the scan directory was deleted when disabling extensions.

    • Fixed misconfiguration which prevented package lists from updating on Linux.

    • Fixed the fallback to install PowerShell packages using Install-Module on Windows when GitHub Releases is down. Also fixed not adding the Import-Module command to the profile when it fallbacks.

    • Fixed tools setup to not overwrite an existing tool with a broken one if it fails to set up.

    • Fixed an error when copying tools to a directory in PATH in tools setup.

    • Fixed parsing composer phars from snapshot channel for its version when is a stable version.

    • Fixed support for oci8 and pdo_oci extensions on Windows.

    • Fixed pecl_http setup.

    • Fixed restore-keys input in composer cache example in README with dependency range.

    • Fixed error in tools setup on self-hosted environments when composer's bin directory is not present.

    • Fixed tools.getLatestVersion to handle failing GitHub API call.

    • Fixed output on non-GitHub Action environments where GitHub Action specific command syntax was printed.

    • Fixed a bug where the status variable was overwritten in ppa.sh and was breaking the status output.

    • Fixed scope of variables to local in bash scripts.

    • Fixed setting extension stability in Add-Extension Function on Windows.

    • Fixed node-release workflow to add lib directory to the packages.

    • Fixed sending coverage data to codecov on pull requests.

    • Refactored utils.fetch to its own module and mocked the http module using nock for fetch tests. Now the Node.js test suite does not make any external requests.

    • Refactored setting environment variables and adding to PATH.

    • Refactored setting outputs to functions with a check to only run on GitHub Actions.

    • Refactored extension functions to add_extension.sh and add_extension.ps1.

    • Refactored the default PHP packages for self-hosted Linux environments to a config file. Also added cgi, fpm, mysql, opcache, pgsql and zip to the list.

    • Refactored Nightly PHP setup to Install-PhpNightly Function on Windows.

    • Refactored CI workflows and templates.

    • Rename common.sh to unix.sh.

    • Update security policy to specify clearly that the latest patch versions of both v1 and v2 are supported for security updates.

    • Updated Node workflows to use 16.x.

    • Updated README for the release.

    • Updated Node.js dependencies.


    Thanks! @​jrfnl and @​villfa for the contributions 🚀

    Follow for updates

    setup-php reddit setup-php twitter setup-php status


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, click this checkbox.

    This PR has been generated by Mend Renovate. View repository job log here.


    This change is Reviewable

    opened by renovate[bot] 5
  • Update shivammathur/setup-php action to v2.16.0

    Update shivammathur/setup-php action to v2.16.0

    WhiteSource Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | shivammathur/setup-php | action | minor | 2.9.0 -> 2.16.0 |


    Release Notes

    shivammathur/setup-php

    v2.16.0

    Compare Source

    This release is possible because of our sponsors. So, if your company uses setup-php, please ask them to sponsor my work.

    Sponsor shivammathur


    • PHP 8.1 is now stable (8.1.0) and marked as the latest version. 🥳
    - name: Setup PHP 8.1
      uses: shivammathur/setup-php@v2
      with:
        php-version: latest
    
    • PHP 7.3 to PHP 8.1 packages have been updated to 7.3.33, 7.4.26, 8.0.13, and 8.1.0 respectively. Set the update environment variable to true for always updating to the latest patch version.
    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      env:
        update: true
      with:
        php-version: '8.0'
    
    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: 7.4
        extensions: intl-70.1
    
    • Add support for mailparse and xlswriter extensions on macOS using shivammathur/extensions tap.
    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: 7.4
        extensions: mailparse, xlswriter
    
    • Fix upgrading nightly versions on self-hosted runners. Now PHP 8.2 will update to the latest build when the update environment variable is set to true.
    • Fix support for brew extensions with different package and extension name.
    • Fix support for Imagick extension on Windows. https://github.com/shivammathur/setup-php/pull/528
    • Fix error while Blackfire configuration file is opened in tool's set up on Linux.
    • Fix extension support to install extension packages from ppa:ondrej/php in php-builder builds.
    • Fix dependency support in self-hosted macOS.
    • Fix to only copy problem-matchers configs to RUNNER_TOOL_CACHE.
    • Fix support for Phalcon extension.
    • Fix CA certificate issues on windows. #​511, #​517
    • Fix to suppress error when extensions are cached on Windows.
    • Log error when wrong Xdebug version is requested as coverage driver for a PHP version. https://github.com/shivammathur/setup-php/issues/519
    • Add patch to support self-hosted environments on Debian 12 or distributions based on it.
    • Add action to limit outbound requests to known endpoints in node workflow.
    • Add links for all tools in the README. https://github.com/shivammathur/setup-php/pull/518
    • Add workflow to publish to NPM and GitHub packages. #​513
    • Use jest.each for extensions and install modules' tests. #​514, #​516,
    • Update Node.js dependencies.

    Thanks! @​jrfnl, @​jderusse, and @​aneeshrelan for the contributions 🚀

    Follow for updates

    setup-php reddit setup-php twitter setup-php status

    v2.15.0

    Compare Source

    Setup PHP depends on sponsorships. Maintaining it takes time and money especially with daily builds for upcoming PHP versions. So, if you found it helpful, please support the project.

    Sponsor shivammathur


    • PHP 5.6 to 7.2 have been rebuilt with patch for CVE-2021-21706 backported from 7.3.31.

    • PHP 7.3 to PHP 8.0 packages have been updated to 7.3.31, 7.4.24 and 8.0.11 respectively. Set the update environment variable to true for always updating to the latest patch version.

    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      env:
        update: true
      with:
        php-version: '8.0'
    
    • Add support for the following tools:

    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.0'
        tools: phpDocumentor, parallel-lint, phpunit-polyfills
    
    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.0'
        extensions: expect, ssh2
    
    • Fix parsing PHP 8.1 version with both RC and dev suffixes in the semver notation.

    • Fix to get correct php-src git ref for nightly builds.

    • Fix version for extensions in logs when installed using PECL.

    • Fix cache support for extensions with custom support. #​496

    • Fix logs for extensions with custom support when cached.

    • Fix PPA setup to add/update list files in /var/lib/apt/lists. #​492

    • Fix typo to use correct key for phpunit in tools.functionRecord. #​501

    • Replace husky with simple-git-hooks.

    • Cleanup trailing whitespace in README.

    • Fix git command in format NPM script.

    • Update Node.js dependencies.


    Thanks @​jrfnl for the contributions 🚀

    Follow for updates

    setup-php reddit setup-php twitter setup-php status

    v2.14.0

    Compare Source

    • Add support for PHP 8.2. #​490, Docs
    • Specifying 8.2 in the php-version input will set up a nightly build of PHP 8.2.0-dev from the master branch of php/php-src.
    - name: Setup PHP 8.2
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.2'
    
    • Add support for the nightly alias for setting up a build from the master branch. #​491, Docs
    • This will also set up PHP 8.2.0-dev from the master branch of php/php-src.
    - name: Setup PHP 8.2
      uses: shivammathur/setup-php@v2
      with:
        php-version: nightly
    
    • Add support to disable all shared extensions. #​487 Docs
    • Specifying none in extensions input will now disable all shared extensions.
    • If none is specified along with other extensions then setup-php will first remove all shared extensions, and then process the other extensions in the input.
    • As part of this feature from now on, shared extensions will just be disabled, and not removed completely.

    ❤️ Thanks! @​sebastianbergmann and @​localheinz for sponsoring this feature.

    - name: Setup PHP without any shared extensions except mbstring
      uses: shivammathur/setup-php@v2
      with:
        php-version: 8.0
        extensions: none, mbstring
    
    • Fix disabling extensions to identify dependent extensions using the Reflection data and disable them as well. For example, disabling PDO will also disable pdo_mysql.

    • Fix warnings in Windows when the required directory is already present.

    • Fix to identify opcache if Zend OPcache is specified in extensions input.

    • Fix Windows script to install PHP 8.2 and future nightly builds correctly.

    • Fix to parse PHP 8.1 semver version.

    • Use shivammathur/extensions tap to install vips extension on macOS.


    Internal
    • Add test cases for ini-values containing special characters to config.test.ts to avoid regression.

    • Add bugs, directories, files and types properties in package.json.

    • Add an SVG with past and present individual sponsors to the README.

    • Use commit hash from the path in URL instead of the query string for nightly builds on macOS.

    • Fix build error in install.ts after TypeScript upgrade.

    • Minor refactor in install.test.ts.

    • Refactor config and coverage test files to use jest.each.

    • Update tsconfig to generate type declarations.

    • Update documentation in the README.

    • Update versions in SECURITY.md.

    • Update Node.js dependencies.

    v2.13.0

    Compare Source

    • Added support for Debian on self-hosted environments and containers.
    • Debian 9 and above are supported in addition to existing Ubuntu support.
    • Operating systems based on these versions of Debian are also supported on a best-effort basis.
    container: debian:bullseye
    steps:
      - name: Install PHP on Debian
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.0'
        env:
          runner: self-hosted
    
    • Added windows-2022 to the supported OS environments.
    runs-on: windows-2022
    steps:
      - name: Install PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.0'
    
    • Added support for phpunit-bridge and updated symfony examples to install it using setup-php.
    - name: Setup PHP with Phive
      with:
        php-version: '8.0'
        tools: phpunit-bridge
    
    • Added documentation to run multi-line PHP code in workflows. #​482
    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.0'
    
    - name: Run PHP code
      shell: php {0}
      run: |
        <?php
        $welcome = "Hello, world";
        echo $welcome;
    
    • Added support for extensions mongodb and yaml on macOS using shivammathur/extensions tap.
    • Added a specific phive version compatible with PHP 7.2. #​481
    - name: Setup PHP with Phive
      uses: shivammathur/setup-php@v2
      with:
        php-version: '7.2'
        tools: phive
    
    • Added --no-install-recommends to apt install commands on Linux.
    • Added support for JavaScript actions on shivammathur/node images. spc is no longer required for multi-arch workflows and normal GitHub Action syntax should work.
    container: shivammathur/node:latest-${{ matrix.arch }}
    strategy:
      matrix:
        arch: ["amd64", "i386"]
    steps:
      - name: Install PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.0'
    
    • PHP 8.1 on Linux in shivammathur/php-builder is now built nightly with the same configuration and patches as official Debian builds of PHP.
    - name: Setup PHP 8.1
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.1'
    
    • Added a new flag NO_TOOLS_CACHE. The tool will be fetched from the source instead of any cache that setup-php implements when this is set to true.
    • This can be useful for maintainers to make sure a new version of their tool is used instead of the old cached version.
    • As of this release, only composer phars are cached.
    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      env:
        NO_TOOLS_CACHE: true
      with:
        php-version: '8.0'
    
    • Removed support for Ubuntu 16.04. Please upgrade to Ubuntu 20.04 or Ubuntu 18.04 environments. #​452
    • Removed support for Blackfire v1. Specifying blackfire in tools will now install the latest version of Blackfire CLI v2. #​478
    - name: Setup PHP with Blackfire
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.0'
        tools: blackfire
    
    • Removed software-properties-common package from dependencies on self-hosted Linux. This package was used for adding third-party repositories(PPA). Removing this reduces self-hosted first run time from 2-3 minutes to 1-2 minutes.

    • PPAs can now be added by setup-php without any dependencies and the deprecated apt-key. It follows the Debian specification for third-party repositories.

    • Remove use of /etc/lsb-release file, /etc/os-release is used now as it has better support.

    • Fixed a bug where the status file was overwritten after PHP was set up on GitHub runners.

    • Fixed support for php-cs-fixer to parse releases.atom file and install correct latest version. #​485

    - name: Setup PHP with php-cs-fixer
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.0'
        tools: php-cs-fixer
    
    • Fixed cache support for extensions on Windows which need additional libraries.
    • Fixed permissions in composer set up on self-hosted environments. #​477
    • Fixed starting Blackfire service on Linux. #​483
    • Fixed a warning about shallow clones for Homebrew taps on macOS.
    • Fixed a warning about macOS developer mode while using brew cat.
    • In tsconfig.json set lib to ES2020 and target to ES2019 for supporting Node 12 in self-hosted runners.
    • Update Node.js dependencies.

    Thanks! @​jrfnl and @​lolautruche for the contributions 🎉

    v2.12.0

    Compare Source

    • Add support to specify major or major.minor versions for tools. Docs, #​467
    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: '7.4'
        tools: php-cs-fixer:3, phpunit:8.5
      env:
        COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    
    • Add a php-version output which can be used in later steps. Docs, #​470
    - name: Setup PHP
      id: setup-php
      uses: shivammathur/setup-php@v2
      with:
        php-version: '7.4'
    
    - name: Print PHP version
      run: echo ${{ steps.setup-php.outputs.php-version }}
    
    • Like Ubuntu, add PHP commit hash in PHP 8.1 (nightly) logs on Windows and macOS.
    • Use composer to install composer-require-checker. #​473
    • Use shivammathur/extensions tap for rdkafka extension on macOS. shivammathur/homebrew-php#​365
    • Support for Ubuntu 16.04 was dropped on August 1, 2021. 📢Announcement: #​452
    • Set the Firebird client version to 3.0.7 on macOS.
    • Improve grpc_php_plugin support on Ubuntu and macOS.
    • Minor fixes for self-hosted setup on Ubuntu.
    • Improve PHP setup on macOS to be more resilient to dependency version inconsistencies.
    • Fix to enable extensions disabled with phpdismod on Ubuntu. actions/virtual-environments#​3472
    • Fix Imagick setup with shivammathur/cache-extensions action on Windows. #​455
    • Fix support for OCI extensions oci8 and pdo_oci. #​449
    • Fix to not use system PHP on macOS.
    • Fix support for Imagick for PHP 5.3 to 5.5 on macOS.
    • Fix installing protoc on macOS.
    • Hotfix: Fix permissions of COMPOSER_HOME directory. #​477
    • Hotfix: Fix support for phive on PHP 7.2. #​481

    Internal
    • Update contributors SVG in README.md to include contributors from setup-php and all related projects.
    • Move tools set up details from tools.ts to tools.json config.
    • Improve error handling in utils.fetch and its uses.
    • Refactor tests for tools using jest.Each.
    • Update Ubuntu 16.04 warning in install.ts.
    • Set sourceMap to true in tsconfig.json.
    • Update Node.js dependencies.

    v2.11.0

    Compare Source

    • Improve cache in shivammathur/php-ubuntu for PHP 5.6 to PHP 8.0. Using cache should reduce setup-php runtime on Ubuntu when the PHP version is not installed on the runner or update: true is set from 1-2 minutes to less than 5 seconds.

    • Add support to compile and install extensions from source from any git repository, from a sub-directory in a repository, with required libraries and configuration. Refer to this guide for more details and examples. #​418, Closes #​419

    • Add support to set up composer packages using tools input. Closes #​442

    - name: Setup PHP with tools
      uses: shivammathur/setup-php@v2
      with:
        php-version: '7.4'
        tools: phpunit/phpunit
    
    • Add support to skip composer setup by specifying tools: none. Closes #​446
    - name: Setup PHP with no tools using composer
      uses: shivammathur/setup-php@v2
      with:
        php-version: '7.4'
        tools: none
    
    • Add support for different ICU versions with PHP 8.1 on Ubuntu.
    - name: Setup PHP 8.1 with ICU 69.1
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.1'
        extensions: intl-69.1
    
    • Improve logs for compiling extensions from source. Now this process is verbose and the logs are grouped.
    • Improve extension support.
      • Add support for pdo_firebird.
      • Improve support for geos to compile on PHP 8.0 and 8.1.
      • Fix cubrid setup on Ubuntu 16.04.
      • Fix gearman support on Ubuntu.
      • Use GitHub releases for all couchbase versions.
      • Use shivammathur/extensions tap for apcu, phalcon, psr, memcache and memcached on macOS.
      • Fix phalcon3 on Windows.
      • Revert to ppa:ondrej/ppa for phalcon3 on Ubuntu.
      • Revert pcov patch for PHP 8 on Windows as the DLL is now available on PECL.
    • Add PHP commit hash in logs on PHP 8.1 (nightly) on Ubuntu. #​433
    • Fix versions in logs of tools installed using composer.
    • Fix linking of old libraries on macOS.
    • Fix enabling cached extensions which have other extensions as dependencies. #​428
    • Fix pecl setup to avoid unnecessary callbacks.
    • Fix blackfire extension version to 1.50.0 for PHP 5.6 and below.
    • Fix composer setup on self-hosted set up. #​435
    • PHP 5.6 to PHP 7.2 on macOS are now built with backported security patches in shivammathur/php tap.

    Internal
    • Add fallback to Install-Module in Install-PSPackage in win32.ps1.
    • Add parameters to add_ppa function in linux.sh.
    • Do not lowercase source extension input.
    • Fix warning about ignored promise in install.ts.
    • Fix shellcheck warning in darwin.sh.
    • Refactor coverage setup.
    • Refactor regex in extension.ts.
    • Remove dotdeb support. PHP 5.4 and 5.5 are now built from source along with compatable extensions in shivammathur/php5-ubuntu.
    • Replace bintray with cdnjs as fallback to GitHub releases for fetching scripts.
    • Replace bintray in Windows script with GitHub Releases.
    • Replace bintray and use shivammathur/intl-icu GitHub releases.
    • Move patches from custom extension scripts to patches directory.
    • Switch from clover.xml to lcov.info for coverage. clover.xml has broken conditional coverage support.
    • Use add_extension_from_source for all custom supported extensions.
    • Move patches from custom extension scripts to patches directory.
    • Move add_pecl_extension to common.sh.
    • Improve switch_version in linux.sh to accept parameters.
    • Cleanup tsconfig.json.
    • Set moduleResolution to node in tsconfig.json.
    • Update year in license.
    • Update Node version to 15.x in Node workflow.
    • Update SECURITY.md.
    • Update Node.js dependencies.

    v2.10.0

    Compare Source

    • Add support to compile extensions from source. Docs (#​399).
    - name: Setup PHP with mongodb compiled from source
      uses: shivammathur/setup-php@v2
      with:
        php-version: '7.4'  
        extensions: mongodb-mongodb/[email protected]
    
    • Add support to setup Xdebug 2.x on PHP 7.2 to PHP 7.4. Docs.
    name: Setup PHP with Xdebug 2.x
    uses: shivammathur/setup-php@v2
    with:
      php-version: '7.4'
      coverage: xdebug2
    
    • Add support for quoted CSV in ini-values to allow directives with commas (#​392, #​405).
    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.0'
        ini-values: xdebug.mode="develop,coverage"
    
    • Add support to specify version in d.x notation. For example 5.x, 7.4 and 8.x (#​395).
    - name: Setup PHP 7.4
      uses: shivammathur/setup-php@v2
      with:
        php-version: '7.x'
    
    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.0'
        extensions: intl-68.2
    
    • Add support for pdo_firebird for all configurations.
    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.0'
        extensions: pdo_firebird
    
    • Add support for self-hosted runners on macOS ARM64 Docs.
    • Add support for blackfire on PHP 8.0.
    - name: Setup PHP with blackfire
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.0'
        extensions: blackfire
        tools: blackfire
    
    • Add support for pecl_http for all PHP versions on Ubuntu and macOS and PHP 7.1 to PHP 8.0 on Windows. (#​396)
    - name: Setup PHP with pecl_http
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.0'
        extensions: pecl_http
    
    • Add support for aliases for symfony-cli, vapor-cli, and wp-cli. Docs
    • Add support for couchbase extension with PHP 5.3 to PHP 5.5 on Ubuntu and macOS.
    • Fail fast on failing to setup the requested PHP version (#​368).
    • Fix Composer config syntax (#​404).
    • Fix PHP 8 on macOS after update on images.
    • Fix PDO extensions setup on Ubuntu and macOS (#​412).
    • Fix compiling extensions in self-hosted workflows (shivammathur/node-docker#​5).
    • Fix tools setup on self-hosted runners.
    • Fix pcov on PHP 8.0 on Windows (#​398).
    • Fix cache support for cubrid and pdo_cubrid.
    • Fix support for phalcon3 (#​413).
    • Improve support for PHP extensions amqp, igbinary, imap, msgpack, propro, raphf, redis and zmq on macOS.
    • Improve support for phive. Now the correct version of phive for the PHP version should be setup (#​366).
    • Improve fetching homebrew taps.
    • Improve PECL support. It is no longer required to specify pecl in tools input.
    • Improve regexes in extensions.ts.
    • Improve logs in Symfony examples (#​377).
    • Set up Codeception using Composer.
    • Change Node.js version in the workflow.
    • Update Node.js dependencies.

    Thanks @​dingo-d, @​alcaeus, @​smoqadam and @​glensc for the contributions 🎉


    Configuration

    📅 Schedule: At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, click this checkbox.

    This PR has been generated by WhiteSource Renovate. View repository job log here.


    This change is Reviewable

    opened by renovate[bot] 5
  • Some invisible characters are not removed

    Some invisible characters are not removed

    What is this feature about (expected vs actual behaviour)?

    Some invisible characters like U+200E are not removed. See https://www.fileformat.info/info/unicode/char/200e/index.htm.

    There could be more.

    How can I reproduce it?

    1. Go to https://emptycharacter.com/
    2. Method 1 - Copy with a button -> Copy to clipboard
    3. \voku\helper\UTF8::remove_invisible_characters('--PASTE IT HERE--')
    4. Expecting empty string, but it returns the input

    Does it take minutes, hours or days to fix?

    Not sure.

    Any additional information?

    bug 
    opened by tormit 5
  • Add 5 failing tests for the most difficult to render Unicode samples.

    Add 5 failing tests for the most difficult to render Unicode samples.

    Fixes # There is no fix yet.

    Proposed Changes

    • Just want to ask if you plan to have those kind of errors get fixed.
    • If yes I can try to find a solution and rework PR.
    • https://github.com/alfredleo/SimpleSolutions Here I have tests with grapheme_substr.

    $ ./vendor/bin/phpunit PHPUnit 7.5.6 by Sebastian Bergmann and contributors. Runtime: PHP 7.2.14 Configuration: C:\Work\libraries\portable-utf8\phpunit.xml Error: No code coverage driver is available ............................................................. 61 / 1792 ( 3%) ............................................................. 122 / 1792 ( 6%) ............................................................. 183 / 1792 ( 10%) ......F...................................................... 244 / 1792 ( 13%) ............................................................. 305 / 1792 ( 17%) ............................................................. 366 / 1792 ( 20%) ............................................................. 427 / 1792 ( 23%) ............................................................. 488 / 1792 ( 27%) ............................................................. 549 / 1792 ( 30%) ............................................................. 610 / 1792 ( 34%) ............................................................. 671 / 1792 ( 37%) ............................................................. 732 / 1792 ( 40%) ............................................................. 793 / 1792 ( 44%) ............................................................. 854 / 1792 ( 47%) ............................................................. 915 / 1792 ( 51%) ............................................................. 976 / 1792 ( 54%) ............................................................. 1037 / 1792 ( 57%) ............................................................. 1098 / 1792 ( 61%) ............................................................. 1159 / 1792 ( 64%) ............................................................. 1220 / 1792 ( 68%) ............................................................. 1281 / 1792 ( 71%) ............................................................. 1342 / 1792 ( 74%) ............................................................. 1403 / 1792 ( 78%) ............................................................. 1464 / 1792 ( 81%) ............................................................. 1525 / 1792 ( 85%) ............................................................. 1586 / 1792 ( 88%) ............................................................. 1647 / 1792 ( 91%) ............................................................. 1708 / 1792 ( 95%) ............................................................. 1769 / 1792 ( 98%) ....................... 1792 / 1792 (100%) Time: 6.65 seconds, Memory: 66.00 MB There was 1 failure: 1) voku\tests\Utf8GlobalNonStrictPart2Test::testStrrev error by 👱👱🏻👱🏼👱🏽👱🏾👱🏿 Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'👱🏿👱🏾👱🏽👱🏼👱🏻👱' +'🏿👱🏾👱🏽👱🏼👱🏻👱👱'


    This change is Reviewable

    opened by alfredleo 5
  • Update actions/cache action to v3.0.6

    Update actions/cache action to v3.0.6

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | actions/cache | action | patch | v3.0.5 -> v3.0.6 |


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, click this checkbox.

    This PR has been generated by Mend Renovate. View repository job log here.


    This change is Reviewable

    opened by renovate[bot] 4
  • Update dependency phpstan/phpstan to 1.9.*@dev

    Update dependency phpstan/phpstan to 1.9.*@dev

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | phpstan/phpstan | require-dev | minor | 1.8.*@dev -> 1.9.*@dev |


    Release Notes

    phpstan/phpstan

    v1.9.2

    Compare Source

    Bugfixes 🐛

    Function signature fixes 🤖

    Internals 🔍

    v1.9.1

    Compare Source

    Improvements 🔧

    Bugfixes 🐛

    v1.9.0

    Compare Source

    Check out the article about this release!

    Major new features 🚀

    Bleeding edge 🔪

    • Array list type (#​1751), #​3311, #​8185, #​6243, thanks @​rvanvelzen!
      • Lists are arrays with sequential integer keys starting at 0
    • Improve error wording of the NonexistentOffset, BooleanAndConstantConditionRule, and BooleanOrConstantConditionRule (#​1882), thanks @​VincentLanglet!
    • MissingMagicSerializationMethodsRule (#​1711), #​7482, thanks @​staabm!
    • Unescape strings in phpdoc-parser (https://github.com/phpstan/phpstan-src/commit/97786ed8376b478ec541ea9df1c450c1fbfe7461)
    • Stub files validation - detect duplicate classes and functions (https://github.com/phpstan/phpstan-src/commit/ddf8d5c3859c2c75c20f525a0e2ca8b99032373a, https://github.com/phpstan/phpstan-src/commit/17e4b74335e5235d7cd6708eb687a774a0eeead4)

    If you want to see the shape of things to come and adopt bleeding edge features early, you can include this config file in your project's phpstan.neon:

    includes:
    	- vendor/phpstan/phpstan/conf/bleedingEdge.neon
    

    Of course, there are no backwards compatibility guarantees when you include this file. The behaviour and reported errors can change in minor versions with this file included. Learn more

    Improvements 🔧

    Bugfixes 🐛

    Function signature fixes 🤖

    Internals 🔍


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.


    This change is Reviewable

    opened by renovate[bot] 2
  • Update shivammathur/setup-php action to v2.22.0

    Update shivammathur/setup-php action to v2.22.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | shivammathur/setup-php | action | minor | 2.21.2 -> 2.22.0 |


    Release Notes

    shivammathur/setup-php

    v2.22.0

    Compare Source

    Support Ukraine

    #StandWithUkraine


    - name: Setup PHP with debugging symbols
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.1'
      env:
        debug: true 
    
    - name: Setup PHP with intl
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.1'
        extensions: intl-72.1
    
    • Existing PHP version on GitHub actions Ubuntu images is now updated if ppa:ondrej/php is missing regardless of the update environment variable. (actions/runner-images#​6331).

    • Environment variable COMPOSER_NO_AUDIT is now set by default. If you would like to run the composer audit in your workflows, please add a step with composer audit command. (#​635, #​636)

    - name: Composer audit
      run: composer audit
    
    • Switched to GITHUB_OUTPUT environment file for setting up outputs. If you are using setup-php on self-hosted runners, please update it to 2.297.0 or greater. More Info (#​654)

    • Updated sqlsrv and pdo_sqlsrv version to 5.10.1 for PHP 7.0 and above on Linux.

    • Improved support for phalcon5 extension to set up the latest stable version.

    • Improved symfony-cli support to fetch the artifact URL from the brew tap on Linux. (#​641, #​652, #​653)

    • Improved fetching brew taps on Linux to avoid brew's overhead.

    • Fixed installing extension packages on self-hosted Linux runners. (#​642)

    • Fixed support for couchbase and firebird extensions after GitHub release page changes.

    • Fixed support for older versions of laravel/pint. (#​647)

    • Updated Node.js dependencies.


    Full Changelog: https://github.com/shivammathur/setup-php/compare/2.21.2...2.22.0

    Thanks! @​alcaeus and @​jderusse for the contributions 🎉

    Follow for updates

    setup-php reddit setup-php twitter setup-php status


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.


    This change is Reviewable

    opened by renovate[bot] 3
  • Update actions/cache action to v3.0.11

    Update actions/cache action to v3.0.11

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | actions/cache | action | patch | v3.0.8 -> v3.0.11 |


    Release Notes

    actions/cache

    v3.0.11

    Compare Source

    What's Changed

    New Contributors

    Full Changelog: https://github.com/actions/cache/compare/v3...v3.0.11

    v3.0.10

    Compare Source

    • Fix a bug with sorting inputs.
    • Update definition for restore-keys in README.md

    v3.0.9

    Compare Source

    • Enhanced the warning message for cache unavailability in case of GHES.

    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.


    This change is Reviewable

    opened by renovate[bot] 2
  • Dependency Dashboard

    Dependency Dashboard

    This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

    Open

    These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

    Detected dependencies

    composer
    build/composer.json
    • voku/php-readme-helper 0.6.*
    composer.json
    • php >=7.0.0
    • symfony/polyfill-php72 ~1.0
    • symfony/polyfill-iconv ~1.0
    • symfony/polyfill-intl-grapheme ~1.0
    • symfony/polyfill-intl-normalizer ~1.0
    • symfony/polyfill-mbstring ~1.0
    • voku/portable-ascii ~2.0.0
    • phpunit/phpunit ~6.0 || ~7.0 || ~9.0
    • phpstan/phpstan 1.8.*@dev
    • phpstan/phpstan-strict-rules 1.4.*@dev
    • thecodingmachine/phpstan-strict-rules 1.0.*@dev
    • voku/phpstan-rules 3.1.*@dev
    github-actions
    .github/workflows/ci.yml
    • actions/checkout v3
    • shivammathur/setup-php 2.21.2
    • actions/cache v3.0.8
    • codecov/codecov-action v3
    • actions/upload-artifact v3

    • [ ] Check this box to trigger a request for Renovate to run again on this repository
    opened by renovate[bot] 0
  • package filesize is pretty big

    package filesize is pretty big

    What is this feature about (expected vs actual behaviour)?

    we integrated this lib with REDAXO CMS project and realized that it is by far the biggest dependency we have. see https://github.com/redaxo/redaxo/issues/4249

    grafik

    major offender is the "data" directory. Tested with 5.4.51

    would it be possible store all the characters in a more space efficient format?

    PS: portable-ascii is the 2nd most space consuming lib in our cms. whatever solution we find for this problem here, could maybe also be applied for portable-ascii.

    How can I reproduce it?

    • make a project depend on portable-utf8
    • run composer install
    • investigate vendor/ dir size

    Does it take minutes, hours or days to fix?

    dont know

    Any additional information?

    opened by staabm 0
  • Activating Open Collective

    Activating Open Collective

    Hi, I'm making updates for Open Collective. Either you or another core contributor signed this repository up for Open Collective. This pull request adds financial contributors from your Open Collective https://opencollective.com/portable-utf8 ❤️

    What it does:

    • adds a badge to show the latest number of financial contributors
    • adds a banner displaying contributors to the project on GitHub
    • adds a banner displaying all individuals contributing financially on Open Collective
    • adds a section displaying all organizations contributing financially on Open Collective, with their logo and a link to their website

    P.S: As with any pull request, feel free to comment or suggest changes.

    Thank you for your great contribution to the Open Source community. You are awesome! 🙌 And welcome to the Open Collective community! 😊

    Come chat with us in the #opensource channel on https://slack.opencollective.com - great place to ask questions and share best practices with other Open Source sustainers!


    This change is Reviewable

    opened by monkeywithacupcake 2
Owner
Lars Moelleken
Webdeveloper & Sysadmin | egrep '#php|#js|#html|#css|#sass'
Lars Moelleken
:accept: Stringy - A PHP string manipulation library with multibyte support, performance optimized

?? Stringy A PHP string manipulation library with multibyte support. Compatible with PHP 7+ 100% compatible with the original "Stringy" library, but t

Lars Moelleken 144 Dec 12, 2022
Extensive, portable and performant handling of UTF-8 and grapheme clusters for PHP

Patchwork UTF-8 for PHP Patchwork UTF-8 gives PHP developpers extensive, portable and performant handling of UTF-8 and grapheme clusters. It provides

Nicolas Grekas 80 Sep 28, 2022
ATOMASTIC 14 Mar 12, 2022
Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way.

String Component The String component provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a un

Symfony 1.3k Dec 29, 2022
Render Persian Text (UTF-8 Hexadecimals)

Persian-Glyphs Purpose This class takes Persian text (encoded in Windows-1256 character set) as input and performs Persian glyph joining on it and out

Rf 3 Aug 25, 2021
A PHP string manipulation library with multibyte support. Compatible with PHP 5.4+, PHP 7+, and HHVM.

A PHP string manipulation library with multibyte support. Compatible with PHP 5.4+, PHP 7+, and HHVM. s('string')->toTitleCase()->ensureRight('y') ==

Daniel St. Jules 2.5k Dec 28, 2022
A PHP string manipulation library with multibyte support

A PHP string manipulation library with multibyte support. Compatible with PHP 5.4+, PHP 7+, and HHVM. s('string')->toTitleCase()->ensureRight('y') ==

Daniel St. Jules 2.5k Jan 3, 2023
PHP library to parse urls from string input

Url highlight - PHP library to parse URLs from string input. Works with complex URLs, edge cases and encoded input. Features: Replace URLs in string b

Volodymyr Stelmakh 77 Sep 16, 2022
A language detection library for PHP. Detects the language from a given text string.

language-detection Build Status Code Coverage Version Total Downloads Minimum PHP Version License This library can detect the language of a given text

Patrick Schur 738 Dec 28, 2022
Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.

Motto: "Every business should have a detection script to detect mobile readers." About Mobile Detect is a lightweight PHP class for detecting mobile d

Şerban Ghiţă 10.2k Jan 4, 2023
Converts a string to a slug. Includes integrations for Symfony, Silex, Laravel, Zend Framework 2, Twig, Nette and Latte.

cocur/slugify Converts a string into a slug. Developed by Florian Eckerstorfer in Vienna, Europe with the help of many great contributors. Features Re

Cocur 2.8k Dec 22, 2022
A sane interface for php's built in preg_* functions

Making regex great again Php's built in preg_* functions require some odd patterns like passing variables by reference and treating false or null valu

Spatie 1.1k Jan 4, 2023
A PHP class which allows the decoding and encoding of a wider variety of characters compared to the standard htmlentities and html_entity_decode functions.

The ability to encode and decode a certain set of characters called 'Html Entities' has existed since PHP4. Amongst the vast number of functions built into PHP, there are 4 nearly identical functions that are used to encode and decode html entities; despite their similarities, however, 2 of them do provide additional capabilities not available to the others.

Gavin G Gordon (Markowski) 2 Nov 12, 2022
SNIA SSS PTS test suite based on SNIA's Solid State Storage Performance Test Specification for Transcend products

SNIA-SSS-PTS ABSTRACT SNIA SSS PTS describes a solid state storage device-level performance test methodology, test suite and reporting format intended

Transcend Information, Inc. 6 Nov 2, 2022
A PHP library for generating universally unique identifiers (UUIDs).

ramsey/uuid A PHP library for generating and working with UUIDs. ramsey/uuid is a PHP library for generating and working with universally unique ident

Ben Ramsey 11.9k Jan 8, 2023
A fast PHP slug generator and transliteration library that converts non-ascii characters for use in URLs.

URLify for PHP A fast PHP slug generator and transliteration library, started as a PHP port of URLify.js from the Django project. Handles symbols from

Aband*nthecar 667 Dec 20, 2022
ColorJizz is a PHP library for manipulating and converting colors.

#Getting started: ColorJizz-PHP uses the PSR-0 standards for namespaces, so there should be no trouble using with frameworks like Symfony 2. ###Autolo

Mikeemoo 281 Nov 25, 2022
PHP library to detect and manipulate indentation of strings and files

indentation PHP library to detect and manipulate the indentation of files and strings Installation composer require --dev colinodell/indentation Usage

Colin O'Dell 34 Nov 28, 2022
The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.

DeviceDetector Code Status Description The Universal Device Detection library that parses User Agents and detects devices (desktop, tablet, mobile, tv

Matomo Analytics 2.4k Jan 5, 2023