Home

Awesome

SWUbanner

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

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

<p id="voku-php-readme-class-methods"></p><table><tr><td><a href="#accessstring-str-int-pos-string-encoding-string">access</a> </td><td><a href="#add_bom_to_stringstring-str-non-empty-string">add_bom_to_string</a> </td><td><a href="#array_change_key_casearray-array-int-case-string-encoding-string">array_change_key_case</a> </td><td><a href="#betweenstring-str-string-start-string-end-int-offset-string-encoding-string">between</a> </td></tr><tr><td><a href="#binary_to_strstring-bin-string">binary_to_str</a> </td><td><a href="#bom-non-empty-string">bom</a> </td><td><a href="#callbackcallablestring-string-callback-string-str-string">callback</a> </td><td><a href="#char_atstring-str-int-index-string-encoding-string">char_at</a> </td></tr><tr><td><a href="#charsstring-str-string">chars</a> </td><td><a href="#checkforsupport-truenull">checkForSupport</a> </td><td><a href="#chrint-code_point-string-encoding-stringnull">chr</a> </td><td><a href="#chr_mapcallablestring-string-callback-string-str-string">chr_map</a> </td></tr><tr><td><a href="#chr_size_liststring-str-int">chr_size_list</a> </td><td><a href="#chr_to_decimalstring-char-int">chr_to_decimal</a> </td><td><a href="#chr_to_hexintstring-char-string-prefix-string">chr_to_hex</a> </td><td><a href="#chunk_splitstring-str-int-chunk_length-string-end-string">chunk_split</a> </td></tr><tr><td><a href="#cleanstring-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">clean</a> </td><td><a href="#cleanupstring-str-string">cleanup</a> </td><td><a href="#codepointsstringstring-arg-bool-use_u_style-intstring">codepoints</a> </td><td><a href="#collapse_whitespacestring-str-string">collapse_whitespace</a> </td></tr><tr><td><a href="#count_charsstring-str-bool-clean_utf8-bool-try_to_use_mb_functions-int">count_chars</a> </td><td><a href="#css_identifierstring-str-string-filter-bool-strip_tags-bool-strtolower-string">css_identifier</a> </td><td><a href="#css_stripe_media_queriesstring-str-string">css_stripe_media_queries</a> </td><td><a href="#ctype_loaded-bool">ctype_loaded</a> </td></tr><tr><td><a href="#decimal_to_chrintstring-int-string">decimal_to_chr</a> </td><td><a href="#decode_mimeheaderstring-str-string-encoding-falsestring">decode_mimeheader</a> </td><td><a href="#emoji_decodestring-str-bool-use_reversible_string_mappings-string">emoji_decode</a> </td><td><a href="#emoji_encodestring-str-bool-use_reversible_string_mappings-string">emoji_encode</a> </td></tr><tr><td><a href="#emoji_from_country_codestring-country_code_iso_3166_1-string">emoji_from_country_code</a> </td><td><a href="#encodestring-to_encoding-string-str-bool-auto_detect_the_from_encoding-string-from_encoding-string">encode</a> </td><td><a href="#encode_mimeheaderstring-str-string-from_charset-string-to_charset-string-transfer_encoding-string-linefeed-int-indent-falsestring">encode_mimeheader</a> </td><td><a href="#extract_textstring-str-string-search-intnull-length-string-replacer_for_skipped_text-string-encoding-string">extract_text</a> </td></tr><tr><td><a href="#file_get_contentsstring-filename-bool-use_include_path-resourcenull-context-intnull-offset-intnull-max_length-int-timeout-bool-convert_to_utf8-string-from_encoding-falsestring">file_get_contents</a> </td><td><a href="#file_has_bomstring-file_path-bool">file_has_bom</a> </td><td><a href="#filterarrayobjectstring-var-int-normalization_form-string-leading_combining-mixed">filter</a> </td><td><a href="#filter_inputint-type-string-variable_name-int-filter-intintnull-options-mixed">filter_input</a> </td></tr><tr><td><a href="#filter_input_arrayint-type-arraynull-definition-bool-add_empty-arraystringmixedfalsenull">filter_input_array</a> </td><td><a href="#filter_varfloatintstringnull-variable-int-filter-intint-options-mixed">filter_var</a> </td><td><a href="#filter_var_arrayarray-data-arrayint-definition-bool-add_empty-arraystringmixedfalsenull">filter_var_array</a> </td><td><a href="#finfo_loaded-bool">finfo_loaded</a> </td></tr><tr><td><a href="#first_charstring-str-int-n-string-encoding-string">first_char</a> </td><td><a href="#fits_insidestring-str-int-box_size-bool">fits_inside</a> </td><td><a href="#fix_simple_utf8string-str-string">fix_simple_utf8</a> </td><td><a href="#fix_utf8stringstring-str-stringstring">fix_utf8</a> </td></tr><tr><td><a href="#getchardirectionstring-char-string">getCharDirection</a> </td><td><a href="#getsupportinfostringnull-key-mixed">getSupportInfo</a> </td><td><a href="#geturlparamfromarraystring-param-array-data-mixed">getUrlParamFromArray</a> </td><td><a href="#get_file_typestring-str-array-fallback">get_file_type</a> </td></tr><tr><td><a href="#get_random_stringint-length-string-possible_chars-string-encoding-string">get_random_string</a> </td><td><a href="#get_unique_stringintstring-extra_entropy-bool-use_md5-non-empty-string">get_unique_string</a> </td><td><a href="#has_lowercasestring-str-bool">has_lowercase</a> </td><td><a href="#has_uppercasestring-str-bool">has_uppercase</a> </td></tr><tr><td><a href="#has_whitespacestring-str-bool">has_whitespace</a> </td><td><a href="#hex_to_chrstring-hexdec-string">hex_to_chr</a> </td><td><a href="#hex_to_intstring-hexdec-falseint">hex_to_int</a> </td><td><a href="#html_encodestring-str-bool-keep_ascii_chars-string-encoding-string">html_encode</a> </td></tr><tr><td><a href="#html_entity_decodestring-str-intnull-flags-string-encoding-string">html_entity_decode</a> </td><td><a href="#html_escapestring-str-string-encoding-string">html_escape</a> </td><td><a href="#html_stripe_empty_tagsstring-str-string">html_stripe_empty_tags</a> </td><td><a href="#htmlentitiesstring-str-int-flags-string-encoding-bool-double_encode-string">htmlentities</a> </td></tr><tr><td><a href="#htmlspecialcharsstring-str-int-flags-string-encoding-bool-double_encode-string">htmlspecialchars</a> </td><td><a href="#iconv_loaded-bool">iconv_loaded</a> </td><td><a href="#int_to_hexint-int-string-prefix-string">int_to_hex</a> </td><td><a href="#intlchar_loaded-bool">intlChar_loaded</a> </td></tr><tr><td><a href="#intl_loaded-bool">intl_loaded</a> </td><td><a href="#is_alphastring-str-bool">is_alpha</a> </td><td><a href="#is_alphanumericstring-str-bool">is_alphanumeric</a> </td><td><a href="#is_asciistring-str-bool">is_ascii</a> </td></tr><tr><td><a href="#is_base64stringnull-str-bool-empty_string_is_valid-bool">is_base64</a> </td><td><a href="#is_binaryintstring-input-bool-strict-bool">is_binary</a> </td><td><a href="#is_binary_filestring-file-bool">is_binary_file</a> </td><td><a href="#is_blankstring-str-bool">is_blank</a> </td></tr><tr><td><a href="#is_bomstring-str-bool">is_bom</a> </td><td><a href="#is_emptyarrayfloatintstring-str-bool">is_empty</a> </td><td><a href="#is_hexadecimalstring-str-bool">is_hexadecimal</a> </td><td><a href="#is_htmlstring-str-bool">is_html</a> </td></tr><tr><td><a href="#is_jsonstring-str-bool-only_array_or_object_results_are_valid-bool">is_json</a> </td><td><a href="#is_lowercasestring-str-bool">is_lowercase</a> </td><td><a href="#is_printablestring-str-bool-ignore_control_characters-bool">is_printable</a> </td><td><a href="#is_punctuationstring-str-bool">is_punctuation</a> </td></tr><tr><td><a href="#is_serializedstring-str-bool">is_serialized</a> </td><td><a href="#is_uppercasestring-str-bool">is_uppercase</a> </td><td><a href="#is_urlstring-url-bool-disallow_localhost-bool">is_url</a> </td><td><a href="#is_utf8intstringstringnull-str-bool-strict-bool">is_utf8</a> </td></tr><tr><td><a href="#is_utf16string-str-bool-check_if_string_is_binary-falseint">is_utf16</a> </td><td><a href="#is_utf32string-str-bool-check_if_string_is_binary-falseint">is_utf32</a> </td><td><a href="#json_decodestring-json-bool-assoc-int-depth-int-options-mixed">json_decode</a> </td><td><a href="#json_encodemixed-value-int-options-int-depth-falsestring">json_encode</a> </td></tr><tr><td><a href="#json_loaded-bool">json_loaded</a> </td><td><a href="#lcfirststring-str-string-encoding-bool-clean_utf8-stringnull-lang-bool-try_to_keep_the_string_length-string">lcfirst</a> </td><td><a href="#lcwordsstring-str-string-exceptions-string-char_list-string-encoding-bool-clean_utf8-stringnull-lang-bool-try_to_keep_the_string_length-string">lcwords</a> </td><td><a href="#levenshteinstring-str1-string-str2-int-insertioncost-int-replacementcost-int-deletioncost-int">levenshtein</a> </td></tr><tr><td><a href="#ltrimstring-str-stringnull-chars-string">ltrim</a> </td><td><a href="#maxstringstring-arg-stringnull">max</a> </td><td><a href="#max_chr_widthstring-str-int">max_chr_width</a> </td><td><a href="#mbstring_loaded-bool">mbstring_loaded</a> </td></tr><tr><td><a href="#minstringstring-arg-stringnull">min</a> </td><td><a href="#normalize_encodingmixed-encoding-mixed-fallback-mixedstring">normalize_encoding</a> </td><td><a href="#normalize_line_endingstring-str-stringstring-replacer-string">normalize_line_ending</a> </td><td><a href="#normalize_mswordstring-str-string">normalize_msword</a> </td></tr><tr><td><a href="#normalize_whitespacestring-str-bool-keep_non_breaking_space-bool-keep_bidi_unicode_controls-bool-normalize_control_characters-string">normalize_whitespace</a> </td><td><a href="#ordstring-chr-string-encoding-int">ord</a> </td><td><a href="#parse_strstring-str-array-result-bool-clean_utf8-bool">parse_str</a> </td><td><a href="#pcre_utf8_support-bool">pcre_utf8_support</a> </td></tr><tr><td><a href="#rangeintstring-var1-intstring-var2-bool-use_ctype-string-encoding-floatint-step-liststring">range</a> </td><td><a href="#rawurldecodestring-str-bool-multi_decode-string">rawurldecode</a> </td><td><a href="#regex_replacestring-str-string-pattern-string-replacement-string-options-string-delimiter-string">regex_replace</a> </td><td><a href="#remove_bomstring-str-string">remove_bom</a> </td></tr><tr><td><a href="#remove_duplicatesstring-str-stringstring-what-string">remove_duplicates</a> </td><td><a href="#remove_htmlstring-str-string-allowable_tags-string">remove_html</a> </td><td><a href="#remove_html_breaksstring-str-string-replacement-string">remove_html_breaks</a> </td><td><a href="#remove_ileftstring-str-string-substring-string-encoding-string">remove_ileft</a> </td></tr><tr><td><a href="#remove_invisible_charactersstring-str-bool-url_encoded-string-replacement-bool-keep_basic_control_characters-string">remove_invisible_characters</a> </td><td><a href="#remove_irightstring-str-string-substring-string-encoding-string">remove_iright</a> </td><td><a href="#remove_leftstring-str-string-substring-string-encoding-string">remove_left</a> </td><td><a href="#remove_rightstring-str-string-substring-string-encoding-string">remove_right</a> </td></tr><tr><td><a href="#replacestring-str-string-search-string-replacement-bool-case_sensitive-string">replace</a> </td><td><a href="#replace_allstring-str-string-search-stringstring-replacement-bool-case_sensitive-string">replace_all</a> </td><td><a href="#replace_diamond_question_markstring-str-string-replacement_char-bool-process_invalid_utf8_chars-string">replace_diamond_question_mark</a> </td><td><a href="#rtrimstring-str-stringnull-chars-string">rtrim</a> </td></tr><tr><td><a href="#showsupportbool-useecho-stringvoid">showSupport</a> </td><td><a href="#single_chr_html_encodestring-char-bool-keep_ascii_chars-string-encoding-string">single_chr_html_encode</a> </td><td><a href="#spaces_to_tabsstring-str-int-tab_length-string">spaces_to_tabs</a> </td><td><a href="#str_camelizestring-str-string-encoding-bool-clean_utf8-stringnull-lang-bool-try_to_keep_the_string_length-string">str_camelize</a> </td></tr><tr><td><a href="#str_capitalize_namestring-str-string">str_capitalize_name</a> </td><td><a href="#str_containsstring-haystack-string-needle-bool-case_sensitive-bool">str_contains</a> </td><td><a href="#str_contains_allstring-haystack-scalar-needles-bool-case_sensitive-bool">str_contains_all</a> </td><td><a href="#str_contains_anystring-haystack-scalar-needles-bool-case_sensitive-bool">str_contains_any</a> </td></tr><tr><td><a href="#str_dasherizestring-str-string-encoding-string">str_dasherize</a> </td><td><a href="#str_delimitstring-str-string-delimiter-string-encoding-bool-clean_utf8-stringnull-lang-bool-try_to_keep_the_string_length-string">str_delimit</a> </td><td><a href="#str_detect_encodingstring-str-falsestring">str_detect_encoding</a> </td><td><a href="#str_ends_withstring-haystack-string-needle-bool">str_ends_with</a> </td></tr><tr><td><a href="#str_ends_with_anystring-str-string-substrings-bool">str_ends_with_any</a> </td><td><a href="#str_ensure_leftstring-str-string-substring">str_ensure_left</a> </td><td><a href="#str_ensure_rightstring-str-string-substring-string">str_ensure_right</a> </td><td><a href="#str_humanizestring-str-string">str_humanize</a> </td></tr><tr><td><a href="#str_iends_withstring-haystack-string-needle-bool">str_iends_with</a> </td><td><a href="#str_iends_with_anystring-str-string-substrings-bool">str_iends_with_any</a> </td><td><a href="#str_insertstring-str-string-substring-int-index-string-encoding-string">str_insert</a> </td><td><a href="#str_ireplacestringstring-search-stringstring-replacement-stringstring-subject-int-count-stringstring">str_ireplace</a> </td></tr><tr><td><a href="#str_ireplace_beginningstring-str-string-search-string-replacement-string">str_ireplace_beginning</a> </td><td><a href="#str_ireplace_endingstring-str-string-search-string-replacement-string">str_ireplace_ending</a> </td><td><a href="#str_istarts_withstring-haystack-string-needle-bool">str_istarts_with</a> </td><td><a href="#str_istarts_with_anystring-str-scalar-substrings-bool">str_istarts_with_any</a> </td></tr><tr><td><a href="#str_isubstr_after_first_separatorstring-str-string-separator-string-encoding-string">str_isubstr_after_first_separator</a> </td><td><a href="#str_isubstr_after_last_separatorstring-str-string-separator-string-encoding-string">str_isubstr_after_last_separator</a> </td><td><a href="#str_isubstr_before_first_separatorstring-str-string-separator-string-encoding-string">str_isubstr_before_first_separator</a> </td><td><a href="#str_isubstr_before_last_separatorstring-str-string-separator-string-encoding-string">str_isubstr_before_last_separator</a> </td></tr><tr><td><a href="#str_isubstr_firststring-str-string-needle-bool-before_needle-string-encoding-string">str_isubstr_first</a> </td><td><a href="#str_isubstr_laststring-str-string-needle-bool-before_needle-string-encoding-string">str_isubstr_last</a> </td><td><a href="#str_last_charstring-str-int-n-string-encoding-string">str_last_char</a> </td><td><a href="#str_limitstring-str-int-length-string-str_add_on-string-encoding-string">str_limit</a> </td></tr><tr><td><a href="#str_limit_after_wordstring-str-int-length-string-str_add_on-string-encoding-string">str_limit_after_word</a> </td><td><a href="#str_longest_common_prefixstring-str1-string-str2-string-encoding-string">str_longest_common_prefix</a> </td><td><a href="#str_longest_common_substringstring-str1-string-str2-string-encoding-string">str_longest_common_substring</a> </td><td><a href="#str_longest_common_suffixstring-str1-string-str2-string-encoding-string">str_longest_common_suffix</a> </td></tr><tr><td><a href="#str_matches_patternstring-str-string-pattern-bool">str_matches_pattern</a> </td><td><a href="#str_obfuscatestring-str-float-percent-string-obfuscatechar-string-keepchars-string">str_obfuscate</a> </td><td><a href="#str_offset_existsstring-str-int-offset-string-encoding-bool">str_offset_exists</a> </td><td><a href="#str_offset_getstring-str-int-index-string-encoding-string">str_offset_get</a> </td></tr><tr><td><a href="#str_padstring-str-int-pad_length-string-pad_string-intstring-pad_type-string-encoding-string">str_pad</a> </td><td><a href="#str_pad_bothstring-str-int-length-string-pad_str-string-encoding-string">str_pad_both</a> </td><td><a href="#str_pad_leftstring-str-int-length-string-pad_str-string-encoding-string">str_pad_left</a> </td><td><a href="#str_pad_rightstring-str-int-length-string-pad_str-string-encoding-string">str_pad_right</a> </td></tr><tr><td><a href="#str_repeatstring-str-int-multiplier-string">str_repeat</a> </td><td><a href="#str_replace_beginningstring-str-string-search-string-replacement-string">str_replace_beginning</a> </td><td><a href="#str_replace_endingstring-str-string-search-string-replacement-string">str_replace_ending</a> </td><td><a href="#str_replace_firststring-search-string-replace-string-subject-string">str_replace_first</a> </td></tr><tr><td><a href="#str_replace_laststring-search-string-replace-string-subject-string">str_replace_last</a> </td><td><a href="#str_shufflestring-str-string-encoding-string">str_shuffle</a> </td><td><a href="#str_slicestring-str-int-start-intnull-end-string-encoding-falsestring">str_slice</a> </td><td><a href="#str_snakeizestring-str-string-encoding-string">str_snakeize</a> </td></tr><tr><td><a href="#str_sortstring-str-bool-unique-bool-desc-string">str_sort</a> </td><td><a href="#str_splitintstring-str-int-length-bool-clean_utf8-bool-try_to_use_mb_functions-liststring">str_split</a> </td><td><a href="#str_split_arrayintstring-input-int-length-bool-clean_utf8-bool-try_to_use_mb_functions-listliststring">str_split_array</a> </td><td><a href="#str_split_patternstring-str-string-pattern-int-limit-string">str_split_pattern</a> </td></tr><tr><td><a href="#str_starts_withstring-haystack-string-needle-bool">str_starts_with</a> </td><td><a href="#str_starts_with_anystring-str-scalar-substrings-bool">str_starts_with_any</a> </td><td><a href="#str_substr_after_first_separatorstring-str-string-separator-string-encoding-string">str_substr_after_first_separator</a> </td><td><a href="#str_substr_after_last_separatorstring-str-string-separator-string-encoding-string">str_substr_after_last_separator</a> </td></tr><tr><td><a href="#str_substr_before_first_separatorstring-str-string-separator-string-encoding-string">str_substr_before_first_separator</a> </td><td><a href="#str_substr_before_last_separatorstring-str-string-separator-string-encoding-string">str_substr_before_last_separator</a> </td><td><a href="#str_substr_firststring-str-string-needle-bool-before_needle-string-encoding-string">str_substr_first</a> </td><td><a href="#str_substr_laststring-str-string-needle-bool-before_needle-string-encoding-string">str_substr_last</a> </td></tr><tr><td><a href="#str_surroundstring-str-string-substring-string">str_surround</a> </td><td><a href="#str_titleizestring-str-stringnull-ignore-string-encoding-bool-clean_utf8-stringnull-lang-bool-try_to_keep_the_string_length-bool-use_trim_first-stringnull-word_define_chars-string">str_titleize</a> </td><td><a href="#str_titleize_for_humansstring-str-string-ignore-string-encoding-string">str_titleize_for_humans</a> </td><td><a href="#str_to_binarystring-str-falsestring">str_to_binary</a> </td></tr><tr><td><a href="#str_to_linesstring-str-bool-remove_empty_values-intnull-remove_short_values-string">str_to_lines</a> </td><td><a href="#str_to_wordsstring-str-string-char_list-bool-remove_empty_values-intnull-remove_short_values-liststring">str_to_words</a> </td><td><a href="#str_truncatestring-str-int-length-string-substring-string-encoding-string">str_truncate</a> </td><td><a href="#str_truncate_safestring-str-int-length-string-substring-string-encoding-bool-ignore_do_not_split_words_for_one_word-string">str_truncate_safe</a> </td></tr><tr><td><a href="#str_underscoredstring-str-string">str_underscored</a> </td><td><a href="#str_upper_camelizestring-str-string-encoding-bool-clean_utf8-stringnull-lang-bool-try_to_keep_the_string_length-string">str_upper_camelize</a> </td><td><a href="#str_word_countstring-str-int-format-string-char_list-intstring">str_word_count</a> </td><td><a href="#strcasecmpstring-str1-string-str2-string-encoding-int">strcasecmp</a> </td></tr><tr><td><a href="#strcmpstring-str1-string-str2-int">strcmp</a> </td><td><a href="#strcspnstring-str-string-char_list-int-offset-intnull-length-string-encoding-int">strcspn</a> </td><td><a href="#stringintintstringstring-intorhex-string">string</a> </td><td><a href="#string_has_bomstring-str-bool">string_has_bom</a> </td></tr><tr><td><a href="#strip_tagsstring-str-stringnull-allowable_tags-bool-clean_utf8-string">strip_tags</a> </td><td><a href="#strip_whitespacestring-str-string">strip_whitespace</a> </td><td><a href="#striposstring-haystack-string-needle-int-offset-string-encoding-bool-clean_utf8-falseint">stripos</a> </td><td><a href="#stripos_in_bytestring-haystack-string-needle-int-offset-falseint">stripos_in_byte</a> </td></tr><tr><td><a href="#stristrstring-haystack-string-needle-bool-before_needle-string-encoding-bool-clean_utf8-falsestring">stristr</a> </td><td><a href="#strlenstring-str-string-encoding-bool-clean_utf8-falseint">strlen</a> </td><td><a href="#strlen_in_bytestring-str-int">strlen_in_byte</a> </td><td><a href="#strnatcasecmpstring-str1-string-str2-string-encoding-int">strnatcasecmp</a> </td></tr><tr><td><a href="#strnatcmpstring-str1-string-str2-int">strnatcmp</a> </td><td><a href="#strncasecmpstring-str1-string-str2-int-len-string-encoding-int">strncasecmp</a> </td><td><a href="#strncmpstring-str1-string-str2-int-len-string-encoding-int">strncmp</a> </td><td><a href="#strpbrkstring-haystack-string-char_list-falsestring">strpbrk</a> </td></tr><tr><td><a href="#strposstring-haystack-intstring-needle-int-offset-string-encoding-bool-clean_utf8-falseint">strpos</a> </td><td><a href="#strpos_in_bytestring-haystack-string-needle-int-offset-falseint">strpos_in_byte</a> </td><td><a href="#strrchrstring-haystack-string-needle-bool-before_needle-string-encoding-bool-clean_utf8-falsestring">strrchr</a> </td><td><a href="#strrevstring-str-string-encoding-string">strrev</a> </td></tr><tr><td><a href="#strrichrstring-haystack-string-needle-bool-before_needle-string-encoding-bool-clean_utf8-falsestring">strrichr</a> </td><td><a href="#strriposstring-haystack-intstring-needle-int-offset-string-encoding-bool-clean_utf8-falseint">strripos</a> </td><td><a href="#strripos_in_bytestring-haystack-string-needle-int-offset-falseint">strripos_in_byte</a> </td><td><a href="#strrposstring-haystack-intstring-needle-int-offset-string-encoding-bool-clean_utf8-falseint">strrpos</a> </td></tr><tr><td><a href="#strrpos_in_bytestring-haystack-string-needle-int-offset-falseint">strrpos_in_byte</a> </td><td><a href="#strspnstring-str-string-mask-int-offset-intnull-length-string-encoding-falseint">strspn</a> </td><td><a href="#strstrstring-haystack-string-needle-bool-before_needle-string-encoding-bool-clean_utf8-falsestring">strstr</a> </td><td><a href="#strstr_in_bytestring-haystack-string-needle-bool-before_needle-falsestring">strstr_in_byte</a> </td></tr><tr><td><a href="#strtocasefoldstring-str-bool-full-bool-clean_utf8-string-encoding-stringnull-lang-bool-lower-string">strtocasefold</a> </td><td><a href="#strtolowerstring-str-string-encoding-bool-clean_utf8-stringnull-lang-bool-try_to_keep_the_string_length-string">strtolower</a> </td><td><a href="#strtoupperstring-str-string-encoding-bool-clean_utf8-stringnull-lang-bool-try_to_keep_the_string_length-string">strtoupper</a> </td><td><a href="#strtrstring-str-stringstring-from-stringstring-to-string">strtr</a> </td></tr><tr><td><a href="#strwidthstring-str-string-encoding-bool-clean_utf8-int">strwidth</a> </td><td><a href="#substrstring-str-int-offset-intnull-length-string-encoding-bool-clean_utf8-falsestring">substr</a> </td><td><a href="#substr_comparestring-str1-string-str2-int-offset-intnull-length-bool-case_insensitivity-string-encoding-int">substr_compare</a> </td><td><a href="#substr_countstring-haystack-string-needle-int-offset-intnull-length-string-encoding-bool-clean_utf8-falseint">substr_count</a> </td></tr><tr><td><a href="#substr_count_in_bytestring-haystack-string-needle-int-offset-intnull-length-falseint">substr_count_in_byte</a> </td><td><a href="#substr_count_simplestring-str-string-substring-bool-case_sensitive-string-encoding-int">substr_count_simple</a> </td><td><a href="#substr_ileftstring-haystack-string-needle-string">substr_ileft</a> </td><td><a href="#substr_in_bytestring-str-int-offset-intnull-length-falsestring">substr_in_byte</a> </td></tr><tr><td><a href="#substr_irightstring-haystack-string-needle-string">substr_iright</a> </td><td><a href="#substr_leftstring-haystack-string-needle-string">substr_left</a> </td><td><a href="#substr_replacestringstring-str-stringstring-replacement-intint-offset-intintnull-length-string-encoding-stringstring">substr_replace</a> </td><td><a href="#substr_rightstring-haystack-string-needle-string-encoding-string">substr_right</a> </td></tr><tr><td><a href="#swapcasestring-str-string-encoding-bool-clean_utf8-string">swapCase</a> </td><td><a href="#symfony_polyfill_used-bool">symfony_polyfill_used</a> </td><td><a href="#tabs_to_spacesstring-str-int-tab_length-string">tabs_to_spaces</a> </td><td><a href="#titlecasestring-str-string-encoding-bool-clean_utf8-stringnull-lang-bool-try_to_keep_the_string_length-string">titlecase</a> </td></tr><tr><td><a href="#to_asciistring-str-string-unknown-bool-strict-string">to_ascii</a> </td><td><a href="#to_booleanboolfloatintstring-str-bool">to_boolean</a> </td><td><a href="#to_filenamestring-str-bool-use_transliterate-string-fallback_char-string">to_filename</a> </td><td><a href="#to_intstring-str-intnull">to_int</a> </td></tr><tr><td><a href="#to_iso8859stringstring-str-stringstring">to_iso8859</a> </td><td><a href="#to_stringfloatintobjectstringnull-input-stringnull">to_string</a> </td><td><a href="#to_utf8stringstring-str-bool-decode_html_entity_to_utf8-stringstring">to_utf8</a> </td><td><a href="#to_utf8_stringstring-str-bool-decode_html_entity_to_utf8-string">to_utf8_string</a> </td></tr><tr><td><a href="#trimstring-str-stringnull-chars-string">trim</a> </td><td><a href="#ucfirststring-str-string-encoding-bool-clean_utf8-stringnull-lang-bool-try_to_keep_the_string_length-string">ucfirst</a> </td><td><a href="#ucwordsstring-str-string-exceptions-string-char_list-string-encoding-bool-clean_utf8-string">ucwords</a> </td><td><a href="#urldecodestring-str-bool-multi_decode-string">urldecode</a> </td></tr><tr><td><a href="#utf8_decodestring-str-bool-keep_utf8_chars-string">utf8_decode</a> </td><td><a href="#utf8_encodestring-str-string">utf8_encode</a> </td><td><a href="#whitespace_table-string">whitespace_table</a> </td><td><a href="#words_limitstring-str-int-limit-string-str_add_on-string">words_limit</a> </td></tr><tr><td><a href="#wordwrapstring-str-int-width-string-break-bool-cut-string">wordwrap</a> </td><td><a href="#wordwrap_per_linestring-str-int-width-string-break-bool-cut-bool-add_final_break-stringnull-delimiter-string">wordwrap_per_line</a> </td><td><a href="#ws-string">ws</a> </td></tr></table>

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

<a href="#voku-php-readme-class-methods"></a> Return the character at the specified position: $str[1] like functionality.

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

Parameters:

Return:


add_bom_to_string(string $str): non-empty-string

<a href="#voku-php-readme-class-methods"></a> 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: <code>UTF8::add_bom_to_string('fòô'); // "\xEF\xBB\xBF" . 'fòô'</code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Changes all keys in an array.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


binary_to_str(string $bin): string

<a href="#voku-php-readme-class-methods"></a> Convert binary into a string.

INFO: opposite to UTF8::str_to_binary()

EXAMPLE: <code>UTF8::binary_to_str('11110000100111111001100010000011'); // '😃'</code>

Parameters:

Return:


bom(): non-empty-string

<a href="#voku-php-readme-class-methods"></a> 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: <code>UTF8::bom(); // "\xEF\xBB\xBF"</code>

Parameters: nothing

Return:


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

<a href="#voku-php-readme-class-methods"></a>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns the character at $index, with indexes starting at 0.

Parameters:

Return:


chars(string $str): string[]

<a href="#voku-php-readme-class-methods"></a> Returns an array consisting of the characters in the string.

Parameters:

Return:


checkForSupport(): true|null

<a href="#voku-php-readme-class-methods"></a> This method will auto-detect your server environment for UTF-8 support.

Parameters: nothing

Return:


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

<a href="#voku-php-readme-class-methods"></a> Generates a UTF-8 encoded character from the given code point.

INFO: opposite to UTF8::ord()

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Applies callback to all characters of a string.

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

Parameters:

Return:


chr_size_list(string $str): int[]

<a href="#voku-php-readme-class-methods"></a> 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: <code>UTF8::chr_size_list('中文空白-test'); // [3, 3, 3, 3, 1, 1, 1, 1, 1]</code>

Parameters:

Return:


chr_to_decimal(string $char): int

<a href="#voku-php-readme-class-methods"></a> Get a decimal code representation of a specific character.

INFO: opposite to UTF8::decimal_to_chr()

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Get hexadecimal code point (U+xxxx) of a UTF-8 encoded character.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Splits a string into smaller chunks and multiple lines, using the specified line ending character.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Accepts a string and removes all non-UTF-8 characters from it + extras if needed.

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

Parameters:

</p>`

Return:


cleanup(string $str): string

<a href="#voku-php-readme-class-methods"></a> Clean-up a string and show only printable UTF-8 chars at the end + fix UTF-8 encoding.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Accepts a string or an array of chars and returns an array of Unicode code points.

INFO: opposite to UTF8::string()

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

Parameters:

Return:

</p>`

collapse_whitespace(string $str): string

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns count of characters used in a string.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Create a valid CSS identifier for e.g. "class"- or "id"-attributes.

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

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

Parameters:

Return:


css_stripe_media_queries(string $str): string

<a href="#voku-php-readme-class-methods"></a> Remove css media-queries.

Parameters:

Return:


ctype_loaded(): bool

<a href="#voku-php-readme-class-methods"></a> Checks whether ctype is available on the server.

Parameters: nothing

Return:


decimal_to_chr(int|string $int): string

<a href="#voku-php-readme-class-methods"></a> Converts an int value into a UTF-8 character.

INFO: opposite to UTF8::string()

EXAMPLE: <code>UTF8::decimal_to_chr(931); // 'Σ'</code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Decodes a MIME header field

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Decodes a string which was encoded by "UTF8::emoji_encode()".

INFO: opposite to UTF8::emoji_encode()

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Encode a string with emoji chars into a non-emoji string.

INFO: opposite to UTF8::emoji_decode()

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

Parameters:

Return:


emoji_from_country_code(string $country_code_iso_3166_1): string

<a href="#voku-php-readme-class-methods"></a> Convert any two-letter country code (ISO 3166-1) to the corresponding Emoji.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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: <code> UTF8::encode('ISO-8859-1', '-ABC-中文空白-'); // '-ABC-????-' // UTF8::encode('UTF-8', '-ABC-中文空白-'); // '-ABC-中文空白-' // UTF8::encode('HTML', '-ABC-中文空白-'); // '-ABC-中文空白-' // UTF8::encode('BASE64', '-ABC-中文空白-'); // 'LUFCQy3kuK3mlofnqbrnmb0t' </code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Create an extract from a sentence, so if the search-string was found, it tries to center in the output.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Reads entire file into a string.

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

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

Parameters:

</p>` - `bool $use_include_path [optional] <p> 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. </p>` - `resource|null $context [optional] <p> 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;. </p>` - `int|null $offset [optional] <p> The offset where the reading starts. </p>` - `int<0, max>|null $max_length [optional] <p> Maximum length of data read. The default is to read until end of file is reached. </p>` - `int $timeout <p>The time in seconds for the timeout.</p>` - `bool $convert_to_utf8 <strong>WARNING!!!</strong> <p>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.</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:


file_has_bom(string $file_path): bool

<a href="#voku-php-readme-class-methods"></a> Checks if a file starts with BOM (Byte Order Mark) character.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> "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: <code> // _GET['foo'] = 'bar'; UTF8::filter_input(INPUT_GET, 'foo', FILTER_UNSAFE_RAW)); // 'bar' </code>

Parameters:

</p>` - `string $variable_name <p> Name of a variable to get. </p>` - `int $filter [optional] <p> The ID of the filter to apply. The manual page lists the available filters. </p>` - `int|int[]|null $options [optional] <p> Associative array of options or bitwise disjunction of flags. If filter accepts options, flags can be provided in "flags" field of array. </p>`

Return:

</p>`

filter_input_array(int $type, array|null $definition, bool $add_empty): array<string,mixed>|false|null

<a href="#voku-php-readme-class-methods"></a> "filter_input_array()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed.

Gets external variables and optionally filters them.

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

Parameters:

</p>` - `array<string, mixed>|null $definition [optional] <p> 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. </p> <p> This parameter can be also an integer holding a filter constant. Then all values in the input array are filtered by this filter. </p>` - `bool $add_empty [optional] <p> Add missing keys as <b>NULL</b> to the return value. </p>`

Return:

</p>`

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

<a href="#voku-php-readme-class-methods"></a> "filter_var()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed.

Filters a variable with a specified filter.

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

Parameters:

</p>` - `int $filter [optional] <p> The ID of the filter to apply. The manual page lists the available filters. </p>` - `int|int[] $options [optional] <p> 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. </p> <p> <code> // 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')); </code> </p>`

Return:


filter_var_array(array $data, array|int $definition, bool $add_empty): array<string,mixed>|false|null

<a href="#voku-php-readme-class-methods"></a> "filter_var_array()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed.

Gets multiple variables and optionally filters them.

EXAMPLE: <code> $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' => 'foo@bar.de' ];

UTF8::filter_var_array($data, $filters, true); // ['name' => 'Κόσμε', 'age' => 18, 'email' => 'foo@bar.de'] </code>

Parameters:

</p>` - `array<string, mixed>|int $definition [optional] <p> 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. </p> <p> This parameter can be also an integer holding a filter constant. Then all values in the input array are filtered by this filter. </p>` - `bool $add_empty [optional] <p> Add missing keys as <b>NULL</b> to the return value. </p>`

Return:

</p>`

finfo_loaded(): bool

<a href="#voku-php-readme-class-methods"></a> Checks whether finfo is available on the server.

Parameters: nothing

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns the first $n characters of the string.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Check if the number of Unicode characters isn't greater than the specified integer.

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

Parameters:

Return:


fix_simple_utf8(string $str): string

<a href="#voku-php-readme-class-methods"></a> 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: <code>UTF8::fix_simple_utf8('Düsseldorf'); // 'Düsseldorf'</code>

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:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Fix a double (or multiple) encoded UTF8 string.

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

Parameters:

Return:


getCharDirection(string $char): string

<a href="#voku-php-readme-class-methods"></a> Get character of a specific character.

EXAMPLE: <code>UTF8::getCharDirection('ا'); // 'RTL'</code>

Parameters:

Return:


getSupportInfo(string|null $key): mixed

<a href="#voku-php-readme-class-methods"></a> Check for php-support.

Parameters:

Return:


getUrlParamFromArray(string $param, array $data): mixed

<a href="#voku-php-readme-class-methods"></a> Get data from an array via array like string.

EXAMPLE: <code>$array['foo'][123] = 'lall'; UTF8::getUrlParamFromArray('foo[123]', $array); // 'lall'</code>

Parameters:

Return:


get_file_type(string $str, array $fallback):

<a href="#voku-php-readme-class-methods"></a> Warning: this method only works for some file-types (png, jpg) if you need more supported types, please use e.g. "finfo"

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a>

Parameters:

Return:


has_lowercase(string $str): bool

<a href="#voku-php-readme-class-methods"></a> Returns true if the string contains a lower case char, false otherwise.

Parameters:

Return:


has_uppercase(string $str): bool

<a href="#voku-php-readme-class-methods"></a> Returns true if the string contains an upper case char, false otherwise.

Parameters:

Return:


has_whitespace(string $str): bool

<a href="#voku-php-readme-class-methods"></a> Returns true if the string contains whitespace, false otherwise.

Parameters:

Return:


hex_to_chr(string $hexdec): string

<a href="#voku-php-readme-class-methods"></a> Converts a hexadecimal value into a UTF-8 character.

INFO: opposite to UTF8::chr_to_hex()

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

Parameters:

Return:


hex_to_int(string $hexdec): false|int

<a href="#voku-php-readme-class-methods"></a> Converts hexadecimal U+xxxx code point representation to integer.

INFO: opposite to UTF8::int_to_hex()

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Converts a UTF-8 string to a series of HTML numbered entities.

INFO: opposite to UTF8::html_decode()

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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: <code>UTF8::html_entity_decode('中文空白'); // '中文空白'</code>

Parameters:

</p>` - `int|null $flags [optional] <p> 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. <table> Available <i>flags</i> constants <tr valign="top"> <td>Constant Name</td> <td>Description</td> </tr> <tr valign="top"> <td><b>ENT_COMPAT</b></td> <td>Will convert double-quotes and leave single-quotes alone.</td> </tr> <tr valign="top"> <td><b>ENT_QUOTES</b></td> <td>Will convert both double and single quotes.</td> </tr> <tr valign="top"> <td><b>ENT_NOQUOTES</b></td> <td>Will leave both double and single quotes unconverted.</td> </tr> <tr valign="top"> <td><b>ENT_HTML401</b></td> <td> Handle code as HTML 4.01. </td> </tr> <tr valign="top"> <td><b>ENT_XML1</b></td> <td> Handle code as XML 1. </td> </tr> <tr valign="top"> <td><b>ENT_XHTML</b></td> <td> Handle code as XHTML. </td> </tr> <tr valign="top"> <td><b>ENT_HTML5</b></td> <td> Handle code as HTML 5. </td> </tr> </table> </p>` - `string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>`

Return:


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

<a href="#voku-php-readme-class-methods"></a> Create a escape html version of the string via "UTF8::htmlspecialchars()".

Parameters:

Return:


html_stripe_empty_tags(string $str): string

<a href="#voku-php-readme-class-methods"></a> Remove empty html-tag.

e.g.: <pre><tag></tag></pre>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Convert all applicable characters to HTML entities: UTF-8 version of htmlentities().

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

Parameters:

</p>` - `int $flags [optional] <p> 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. <table> Available <i>flags</i> constants <tr valign="top"> <td>Constant Name</td> <td>Description</td> </tr> <tr valign="top"> <td><b>ENT_COMPAT</b></td> <td>Will convert double-quotes and leave single-quotes alone.</td> </tr> <tr valign="top"> <td><b>ENT_QUOTES</b></td> <td>Will convert both double and single quotes.</td> </tr> <tr valign="top"> <td><b>ENT_NOQUOTES</b></td> <td>Will leave both double and single quotes unconverted.</td> </tr> <tr valign="top"> <td><b>ENT_IGNORE</b></td> <td> Silently discard invalid code unit sequences instead of returning an empty string. Using this flag is discouraged as it may have security implications. </td> </tr> <tr valign="top"> <td><b>ENT_SUBSTITUTE</b></td> <td> Replace invalid code unit sequences with a Unicode Replacement Character U+FFFD (UTF-8) or &#38;#38;#FFFD; (otherwise) instead of returning an empty string. </td> </tr> <tr valign="top"> <td><b>ENT_DISALLOWED</b></td> <td> Replace invalid code points for the given document type with a Unicode Replacement Character U+FFFD (UTF-8) or &#38;#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. </td> </tr> <tr valign="top"> <td><b>ENT_HTML401</b></td> <td> Handle code as HTML 4.01. </td> </tr> <tr valign="top"> <td><b>ENT_XML1</b></td> <td> Handle code as XML 1. </td> </tr> <tr valign="top"> <td><b>ENT_XHTML</b></td> <td> Handle code as XHTML. </td> </tr> <tr valign="top"> <td><b>ENT_HTML5</b></td> <td> Handle code as HTML 5. </td> </tr> </table> </p>` - `string $encoding [optional] <p> Like <b>htmlspecialchars</b>, <b>htmlentities</b> takes an optional third argument <i>encoding</i> which defines encoding used in conversion. Although this argument is technically optional, you are highly encouraged to specify the correct value for your code. </p>` - `bool $double_encode [optional] <p> When <i>double_encode</i> is turned off PHP will not encode existing html entities. The default is to convert everything. </p>`

Return:

</p>`

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

<a href="#voku-php-readme-class-methods"></a> Convert only special characters to HTML entities: UTF-8 version of htmlspecialchars()

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

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

Parameters:

</p>` - `int $flags [optional] <p> 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. <table> Available <i>flags</i> constants <tr valign="top"> <td>Constant Name</td> <td>Description</td> </tr> <tr valign="top"> <td><b>ENT_COMPAT</b></td> <td>Will convert double-quotes and leave single-quotes alone.</td> </tr> <tr valign="top"> <td><b>ENT_QUOTES</b></td> <td>Will convert both double and single quotes.</td> </tr> <tr valign="top"> <td><b>ENT_NOQUOTES</b></td> <td>Will leave both double and single quotes unconverted.</td> </tr> <tr valign="top"> <td><b>ENT_IGNORE</b></td> <td> Silently discard invalid code unit sequences instead of returning an empty string. Using this flag is discouraged as it may have security implications. </td> </tr> <tr valign="top"> <td><b>ENT_SUBSTITUTE</b></td> <td> Replace invalid code unit sequences with a Unicode Replacement Character U+FFFD (UTF-8) or &#38;#38;#FFFD; (otherwise) instead of returning an empty string. </td> </tr> <tr valign="top"> <td><b>ENT_DISALLOWED</b></td> <td> Replace invalid code points for the given document type with a Unicode Replacement Character U+FFFD (UTF-8) or &#38;#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. </td> </tr> <tr valign="top"> <td><b>ENT_HTML401</b></td> <td> Handle code as HTML 4.01. </td> </tr> <tr valign="top"> <td><b>ENT_XML1</b></td> <td> Handle code as XML 1. </td> </tr> <tr valign="top"> <td><b>ENT_XHTML</b></td> <td> Handle code as XHTML. </td> </tr> <tr valign="top"> <td><b>ENT_HTML5</b></td> <td> Handle code as HTML 5. </td> </tr> </table> </p>` - `string $encoding [optional] <p> Defines encoding used in conversion. </p> <p> 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 <i>string</i> itself is valid for the encoding, as the characters affected by <b>htmlspecialchars</b> occupy the same positions in all of these encodings. </p>` - `bool $double_encode [optional] <p> When <i>double_encode</i> is turned off PHP will not encode existing html entities, the default is to convert everything. </p>`

Return:

<p> If the input <i>string</i> contains an invalid code unit sequence within the given <i>encoding</i> an empty string will be returned, unless either the <b>ENT_IGNORE</b> or <b>ENT_SUBSTITUTE</b> flags are set.</p>`

iconv_loaded(): bool

<a href="#voku-php-readme-class-methods"></a> Checks whether iconv is available on the server.

Parameters: nothing

Return:


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

<a href="#voku-php-readme-class-methods"></a> Converts Integer to hexadecimal U+xxxx code point representation.

INFO: opposite to UTF8::hex_to_int()

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

Parameters:

Return:


intlChar_loaded(): bool

<a href="#voku-php-readme-class-methods"></a> Checks whether intl-char is available on the server.

Parameters: nothing

Return:


intl_loaded(): bool

<a href="#voku-php-readme-class-methods"></a> Checks whether intl is available on the server.

Parameters: nothing

Return:


is_alpha(string $str): bool

<a href="#voku-php-readme-class-methods"></a> Returns true if the string contains only alphabetic chars, false otherwise.

Parameters:

Return:


is_alphanumeric(string $str): bool

<a href="#voku-php-readme-class-methods"></a> Returns true if the string contains only alphabetic and numeric chars, false otherwise.

Parameters:

Return:


is_ascii(string $str): bool

<a href="#voku-php-readme-class-methods"></a> Checks if a string is 7 bit ASCII.

EXAMPLE: <code>UTF8::is_ascii('白'); // false</code>

Parameters:

Return:

</p>`

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

<a href="#voku-php-readme-class-methods"></a> Returns true if the string is base64 encoded, false otherwise.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Check if the input is binary... (is look like a hack).

EXAMPLE: <code>UTF8::is_binary(01); // true</code>

Parameters:

Return:


is_binary_file(string $file): bool

<a href="#voku-php-readme-class-methods"></a> Check if the file is binary.

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

Parameters:

Return:


is_blank(string $str): bool

<a href="#voku-php-readme-class-methods"></a> Returns true if the string contains only whitespace chars, false otherwise.

Parameters:

Return:


is_bom(string $str): bool

<a href="#voku-php-readme-class-methods"></a> 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: <code>UTF8::is_bom("\xef\xbb\xbf"); // true</code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


is_hexadecimal(string $str): bool

<a href="#voku-php-readme-class-methods"></a> Returns true if the string contains only hexadecimal chars, false otherwise.

Parameters:

Return:


is_html(string $str): bool

<a href="#voku-php-readme-class-methods"></a> Check if the string contains any HTML tags.

EXAMPLE: <code>UTF8::is_html('<b>lall</b>'); // true</code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Try to check if "$str" is a JSON-string.

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

Parameters:

Return:


is_lowercase(string $str): bool

<a href="#voku-php-readme-class-methods"></a>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns true if the string contains only printable (non-invisible) chars, false otherwise.

Parameters:

Return:


is_punctuation(string $str): bool

<a href="#voku-php-readme-class-methods"></a> Returns true if the string contains only punctuation chars, false otherwise.

Parameters:

Return:


is_serialized(string $str): bool

<a href="#voku-php-readme-class-methods"></a> Returns true if the string is serialized, false otherwise.

Parameters:

Return:


is_uppercase(string $str): bool

<a href="#voku-php-readme-class-methods"></a> Returns true if the string contains only lower case chars, false otherwise.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Check if $url is an correct url.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Checks whether the passed input contains only byte sequences that appear valid UTF-8.

EXAMPLE: <code> 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 </code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Check if the string is UTF-16.

EXAMPLE: <code> 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 </code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Check if the string is UTF-32.

EXAMPLE: <code> 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 </code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> (PHP 5 >= 5.2.0, PECL json >= 1.2.0)<br/> Decodes a JSON string

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

Parameters:

</p> <p> This function only works with UTF-8 encoded strings. </p> <p>PHP implements a superset of JSON - it will also encode and decode scalar types and <b>NULL</b>. The JSON standard only supports these values when they are nested inside an array or an object. </p>` - `bool $assoc [optional] <p> When <b>TRUE</b>, returned objects will be converted into associative arrays. </p>` - `int $depth [optional] <p> User specified recursion depth. </p>` - `int $options [optional] <p> Bitmask of JSON decode options. Currently only <b>JSON_BIGINT_AS_STRING</b> is supported (default is to cast large integers as floats) </p>`

Return:


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

<a href="#voku-php-readme-class-methods"></a> (PHP 5 >= 5.2.0, PECL json >= 1.2.0)<br/> Returns the JSON representation of a value.

EXAMPLE: <code>UTF8::json_encode(array(1, '¥', 'ä')); // '[1,"\u00a5","\u00e4"]'</code>

Parameters:

</p> <p> All string data must be UTF-8 encoded. </p> <p>PHP implements a superset of JSON - it will also encode and decode scalar types and <b>NULL</b>. The JSON standard only supports these values when they are nested inside an array or an object. </p>` - `int $options [optional] <p> Bitmask consisting of <b>JSON_HEX_QUOT</b>, <b>JSON_HEX_TAG</b>, <b>JSON_HEX_AMP</b>, <b>JSON_HEX_APOS</b>, <b>JSON_NUMERIC_CHECK</b>, <b>JSON_PRETTY_PRINT</b>, <b>JSON_UNESCAPED_SLASHES</b>, <b>JSON_FORCE_OBJECT</b>, <b>JSON_UNESCAPED_UNICODE</b>. The behaviour of these constants is described on the JSON constants page. </p>` - `int $depth [optional] <p> Set the maximum depth. Must be greater than zero. </p>`

Return:


json_loaded(): bool

<a href="#voku-php-readme-class-methods"></a> Checks whether JSON is available on the server.

Parameters: nothing

Return:


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

<a href="#voku-php-readme-class-methods"></a> Makes string's first char lowercase.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Lowercase for all words in the string.

Parameters:

Return:


levenshtein(string $str1, string $str2, int $insertionCost, int $replacementCost, int $deletionCost): int

<a href="#voku-php-readme-class-methods"></a> Calculate Levenshtein distance between two strings.

For better performance, in a real application with a single input string matched against many strings from a database, you will probably want to pre- encode the input only once and use \levenshtein().

Source: https://github.com/KEINOS/mb_levenshtein

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Strip whitespace or other characters from the beginning of a UTF-8 string.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns the UTF-8 character with the maximum code point in the given data.

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

Parameters:

Return:


max_chr_width(string $str): int

<a href="#voku-php-readme-class-methods"></a> Calculates and returns the maximum number of bytes taken by any UTF-8 encoded character in the given string.

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

Parameters:

Return:


mbstring_loaded(): bool

<a href="#voku-php-readme-class-methods"></a> Checks whether mbstring is available on the server.

Parameters: nothing

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns the UTF-8 character with the minimum code point in the given data.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Normalize the encoding-"name" input.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Standardize line ending to unix-like.

Parameters:

Return:


normalize_msword(string $str): string

<a href="#voku-php-readme-class-methods"></a> Normalize some MS Word special characters.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Normalize the whitespace.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Calculates Unicode code point of the given UTF-8 encoded character.

INFO: opposite to UTF8::chr()

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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: <code> 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']; // '測試' </code>

Parameters:

Return:


pcre_utf8_support(): bool

<a href="#voku-php-readme-class-methods"></a> Checks if \u modifier is available that enables Unicode support in PCRE.

Parameters: nothing

Return:

</p>`

range(int|string $var1, int|string $var2, bool $use_ctype, string $encoding, float|int $step): list<string>

<a href="#voku-php-readme-class-methods"></a> Create an array containing a range of UTF-8 characters.

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

Parameters:

</p>`

Return:


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

<a href="#voku-php-readme-class-methods"></a> Multi decode HTML entity + fix urlencoded-win1252-chars.

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

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:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Replaces all occurrences of $pattern in $str by $replacement.

Parameters:

Return:


remove_bom(string $str): string

<a href="#voku-php-readme-class-methods"></a> Remove the BOM from UTF-8 / UTF-16 / UTF-32 strings.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Removes duplicate occurrences of a string in another string.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Remove html via "strip_tags()" from the string.

Parameters:

</p>`

Return:


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

<a href="#voku-php-readme-class-methods"></a> Remove all breaks [<br> | \r\n | \r | \n | ...] from the string.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns a new string with the prefix $substring removed, if present and case-insensitive.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Remove invisible characters from a string.

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

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

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

Parameters:

Default: false

</p>` - `string $replacement [optional] <p>The replacement character.</p>` - `bool $keep_basic_control_characters [optional] <p>Keep control characters like [LRM] or [LSEP].</p>`

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns a new string with the suffix $substring removed, if present and case-insensitive.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns a new string with the prefix $substring removed, if present.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns a new string with the suffix $substring removed, if present.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Replaces all occurrences of $search in $str by $replacement.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Replaces all occurrences of $search in $str by $replacement.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Replace the diamond question mark (�) and invalid-UTF8 chars with the replacement.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Strip whitespace or other characters from the end of a UTF-8 string.

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

Parameters:

Return:


showSupport(bool $useEcho): string|void

<a href="#voku-php-readme-class-methods"></a> WARNING: Print native UTF-8 support (libs) by default, e.g. for debugging.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Converts a UTF-8 character to HTML Numbered Entity like "{".

EXAMPLE: <code>UTF8::single_chr_html_encode('κ'); // 'κ'</code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


str_capitalize_name(string $str): string

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


str_contains_all(string $haystack, scalar[] $needles, bool $case_sensitive): bool

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


str_contains_any(string $haystack, scalar[] $needles, bool $case_sensitive): bool

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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.

EXAMPLE: <code> UTF8::str_delimit('test case, '#'); // 'test#case' UTF8::str_delimit('test -case', ''); // 'testcase' </code>

Parameters:

Return:


str_detect_encoding(string $str): false|string

<a href="#voku-php-readme-class-methods"></a> Optimized "mb_detect_encoding()"-function -> with support for UTF-16 and UTF-32.

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

Parameters:

Return:

</p>`

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

<a href="#voku-php-readme-class-methods"></a> Check if the string ends with the given substring.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns true if the string ends with any of $substrings, false otherwise.

Parameters:

Return:


str_ensure_left(string $str, string $substring):

<a href="#voku-php-readme-class-methods"></a> Ensures that the string begins with $substring. If it doesn't, it's prepended.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Ensures that the string ends with $substring. If it doesn't, it's appended.

Parameters:

Return:


str_humanize(string $str): string

<a href="#voku-php-readme-class-methods"></a> Capitalizes the first word of the string, replaces underscores with spaces, and strips '_id'.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Check if the string ends with the given substring, case-insensitive.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns true if the string ends with any of $substrings, false otherwise.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Inserts $substring into the string at the $index provided.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Case-insensitive and UTF-8 safe version of <function>str_replace</function>.

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

Parameters:

</p>` - `string|string[] $replacement <p>The replacement.</p>` - `TStrIReplaceSubject $subject <p> 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. </p>` - `int $count [optional] <p> The number of matched and replaced needles will be returned in count which is passed by reference. </p>`

Return:


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

<a href="#voku-php-readme-class-methods"></a> Replaces $search from the beginning of string with $replacement.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Replaces $search from the ending of string with $replacement.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Check if the string starts with the given substring, case-insensitive.

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

Parameters:

Return:


str_istarts_with_any(string $str, scalar[] $substrings): bool

<a href="#voku-php-readme-class-methods"></a> Returns true if the string begins with any of $substrings, false otherwise.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Gets the substring after the first occurrence of a separator.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Gets the substring after the last occurrence of a separator.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Gets the substring before the first occurrence of a separator.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Gets the substring before the last occurrence of a separator.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Gets the substring after (or before via "$before_needle") the first occurrence of the "$needle".

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Gets the substring after (or before via "$before_needle") the last occurrence of the "$needle".

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns the last $n characters of the string.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Limit the number of characters in a string.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Limit the number of characters in a string, but also after the next word.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns the longest common prefix between the $str1 and $str2.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns the longest common substring between the $str1 and $str2.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns the longest common suffix between the $str1 and $str2.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns true if $str matches the supplied pattern, false otherwise.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Convert a string into a obfuscate string.

EXAMPLE: <code>

UTF8::str_obfuscate('lars@moelleken.org', 0.5, '', ['@', '.']); // e.g. "l**@m**lleke*.r" </code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Pad a UTF-8 string to a given length with another string.

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

Parameters:

</p>` - `string $encoding [optional] <p>Default: 'UTF-8'</p>`

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Repeat a string.

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

Parameters:

</p>` - `int<1, max> $multiplier <p> Number of time the input string should be repeated. </p> <p> multiplier has to be greater than or equal to 0. If the multiplier is set to 0, the function will return an empty string. </p>`

Return:


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

<a href="#voku-php-readme-class-methods"></a> Replaces $search from the beginning of string with $replacement.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Replaces $search from the ending of string with $replacement.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Replace the first "$search"-term with the "$replace"-term.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Replace the last "$search"-term with the "$replace"-term.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Shuffles all the characters in the string.

INFO: uses random algorithm which is weak for cryptography purposes

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Convert a string to e.g.: "snake_case"

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Sort all characters according to code points.

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

Parameters:

Return:


str_split(int|string $str, int $length, bool $clean_utf8, bool $try_to_use_mb_functions): list<string>

<a href="#voku-php-readme-class-methods"></a> Convert a string to an array of unicode characters.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Convert a string to an array of Unicode characters.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Splits the string with the provided regular expression, returning an array of strings. An optional integer $limit will truncate the results.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Check if the string starts with the given substring.

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

Parameters:

Return:


str_starts_with_any(string $str, scalar[] $substrings): bool

<a href="#voku-php-readme-class-methods"></a> Returns true if the string begins with any of $substrings, false otherwise.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Gets the substring after the first occurrence of a separator.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Gets the substring after the last occurrence of a separator.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Gets the substring before the first occurrence of a separator.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Gets the substring before the last occurrence of a separator.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Gets the substring after (or before via "$before_needle") the first occurrence of the "$needle".

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Gets the substring after (or before via "$before_needle") the last occurrence of the "$needle".

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Surrounds $str with the given substring.

Parameters:

Return:


str_titleize(string $str, 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

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


str_titleize_for_humans(string $str, string[] $ignore, string $encoding): string

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


str_to_binary(string $str): false|string

<a href="#voku-php-readme-class-methods"></a> Get a binary representation of a specific string.

EXAPLE: <code>UTF8::str_to_binary('😃'); // '11110000100111111001100010000011'</code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a>

Parameters:

Return:


str_to_words(string $str, string $char_list, bool $remove_empty_values, int|null $remove_short_values): list<string>

<a href="#voku-php-readme-class-methods"></a> Convert a string into an array of words.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


str_underscored(string $str): string

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Get the number of words in a specific string.

EXAMPLES: <code> // 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') </code>

Parameters:

</p>` - `string $char_list [optional] <p>Additional chars that contains to words and do not start a new word.</p>`

Return:


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

<a href="#voku-php-readme-class-methods"></a> Case-insensitive string comparison.

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

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Case-sensitive string comparison.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Find length of initial segment not matching mask.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Create a UTF-8 string from code points.

INFO: opposite to UTF8::codepoints()

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

Parameters:

Return:


string_has_bom(string $str): bool

<a href="#voku-php-readme-class-methods"></a> Checks if string starts with "BOM" (Byte Order Mark Character) character.

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

Parameters:

Return:

</p>`

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

<a href="#voku-php-readme-class-methods"></a> Strip HTML and PHP tags from a string + clean invalid UTF-8.

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

Parameters:

</p>` - `string|null $allowable_tags [optional] <p> You can use the optional second parameter to specify tags which should not be stripped. </p> <p> HTML comments and PHP tags are also stripped. This is hardcoded and can not be changed with allowable_tags. </p>` - `bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>`

Return:


strip_whitespace(string $str): string

<a href="#voku-php-readme-class-methods"></a> Strip all whitespace characters. This includes tabs and newline characters, as well as multibyte whitespace such as the thin space and ideographic space.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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: <code>UTF8::stripos('aσσb', 'ΣΣ'); // 1</code> (σσ == ΣΣ)

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Find the position of the first occurrence of a substring in a string, case-insensitive.

Parameters:

</p>` - `string $needle <p> The position counted from the beginning of haystack. </p>` - `int $offset [optional] <p> The search offset. If it is not specified, 0 is used. </p>`

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns all of haystack starting from and including the first occurrence of needle to the end.

EXAMPLE: <code> $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' </code>

Parameters:

</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:


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

<a href="#voku-php-readme-class-methods"></a> Get the string length, not the byte-length!

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

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

Parameters:

Return:

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

</p>`

strlen_in_byte(string $str): int

<a href="#voku-php-readme-class-methods"></a> Get string length in byte.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Case-insensitive string comparisons using a "natural order" algorithm.

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

EXAMPLES: <code> 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 </code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> String comparisons using a "natural order" algorithm

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

EXAMPLES: <code> 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 </code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Case-insensitive string comparison of the first n characters.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> String comparison of the first n characters.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Search a string for any of a set of characters.

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Find the position of the first occurrence of a substring in a string.

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

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

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Find the position of the first occurrence of a substring in a string.

Parameters:

</p>` - `string $needle <p> The position counted from the beginning of haystack. </p>` - `int $offset [optional] <p> The search offset. If it is not specified, 0 is used. </p>`

Return:


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

<a href="#voku-php-readme-class-methods"></a> Find the last occurrence of a character in a string within another.

EXAMPLE: <code>UTF8::strrchr('κόσμεκόσμε-äöü', 'κόσμε'); // 'κόσμε-äöü'</code>

Parameters:

</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:


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

<a href="#voku-php-readme-class-methods"></a> Reverses characters order in the string.

EXAMPLE: <code>UTF8::strrev('κ-öäü'); // 'üäö-κ'</code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Find the last occurrence of a character in a string within another, case-insensitive.

EXAMPLE: <code>UTF8::strrichr('Aκόσμεκόσμε-äöü', 'aκόσμε'); // 'Aκόσμεκόσμε-äöü'</code>

Parameters:

</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:


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

<a href="#voku-php-readme-class-methods"></a> Find the position of the last occurrence of a substring in a string, case-insensitive.

EXAMPLE: <code>UTF8::strripos('ABC-ÖÄÜ-中文空白-中文空白', '中'); // 13</code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Finds position of last occurrence of a string within another, case-insensitive.

Parameters:

</p>` - `string $needle <p> The string to find in haystack. </p>` - `int $offset [optional] <p> The position in haystack to start searching. </p>`

Return:


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

<a href="#voku-php-readme-class-methods"></a> Find the position of the last occurrence of a substring in a string.

EXAMPLE: <code>UTF8::strrpos('ABC-ÖÄÜ-中文空白-中文空白', '中'); // 13</code>

Parameters:

</p>` - `string $encoding [optional] <p>Set the charset.</p>` - `bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>`

Return:


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

<a href="#voku-php-readme-class-methods"></a> Find the position of the last occurrence of a substring in a string.

Parameters:

</p>` - `string $needle <p> The string to find in haystack. </p>` - `int $offset [optional] <p>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. </p>`

Return:


strspn(string $str, string $mask, int $offset, int|null $length, string $encoding): false|int

<a href="#voku-php-readme-class-methods"></a> Finds the length of the initial segment of a string consisting entirely of characters contained within a given mask.

EXAMPLE: <code>UTF8::strspn('iñtërnâtiônàlizætiøn', 'itñ'); // '3'</code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Returns part of haystack string from the first occurrence of needle to the end of haystack.

EXAMPLE: <code> $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' </code>

Parameters:

</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:


strstr_in_byte(string $haystack, string $needle, bool $before_needle): false|string

<a href="#voku-php-readme-class-methods"></a> Finds first occurrence of a string within another.

Parameters:

</p>` - `string $needle <p> The string to find in haystack. </p>` - `bool $before_needle [optional] <p> 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, </p>`

Return:


strtocasefold(string $str, bool $full, bool $clean_utf8, string $encoding, string|null $lang, bool $lower): string

<a href="#voku-php-readme-class-methods"></a> Unicode transformation for case-less matching.

EXAMPLE: <code>UTF8::strtocasefold('ǰ◌̱'); // 'ǰ◌̱'</code>

Parameters:

</p>` - `bool $clean_utf8 [optional] <p>Remove non UTF-8 chars from the string.</p>` - `string $encoding [optional] <p>Set the charset.</p>` - `string|null $lang [optional] <p>Set the language for special cases: az, el, lt, tr</p>` - `bool $lower [optional] <p>Use lowercase string, otherwise use uppercase string. PS: uppercase is for some languages better ...</p>`

Return:


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

<a href="#voku-php-readme-class-methods"></a> Make a string lowercase.

EXAMPLE: <code>UTF8::strtolower('DÉJÀ Σσς Iıİi'); // 'déjà σσς iıii'</code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Make a string uppercase.

EXAMPLE: <code>UTF8::strtoupper('Déjà Σσς Iıİi'); // 'DÉJÀ ΣΣΣ IIİI'</code>

Parameters:

Return:


strtr(string $str, string|string[] $from, string|string[] $to): string

<a href="#voku-php-readme-class-methods"></a> Translate characters or replace sub-strings.

EXAMPLE: <code> $array = [ 'Hello' => '○●◎', '中文空白' => 'earth', ]; UTF8::strtr('Hello 中文空白', $array); // '○●◎ earth' </code>

Parameters:

Return:


strwidth(string $str, string $encoding, bool $clean_utf8): int

<a href="#voku-php-readme-class-methods"></a> Return the width of a string.

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

EXAMPLE: <code>UTF8::strwidth("Iñtërnâtiôn\xE9àlizætiøn")); // 21</code>

Parameters:

Return:


substr(string $str, int $offset, int|null $length, string $encoding, bool $clean_utf8): false|string

<a href="#voku-php-readme-class-methods"></a> Get part of a string.

EXAMPLE: <code>UTF8::substr('中文空白', 1, 2); // '文空'</code>

Parameters:

Return:


substr_compare(string $str1, string $str2, int $offset, int|null $length, bool $case_insensitivity, string $encoding): int

<a href="#voku-php-readme-class-methods"></a> Binary-safe comparison of two strings from an offset, up to a length of characters.

EXAMPLE: <code> UTF8::substr_compare("○●◎\r", '●◎', 0, 2); // -1 UTF8::substr_compare("○●◎\r", '◎●', 1, 2); // 1 UTF8::substr_compare("○●◎\r", '●◎', 1, 2); // 0 </code>

Parameters:

Return:


substr_count(string $haystack, string $needle, int $offset, int|null $length, string $encoding, bool $clean_utf8): false|int

<a href="#voku-php-readme-class-methods"></a> Count the number of substring occurrences.

EXAMPLE: <code>UTF8::substr_count('中文空白', '文空', 1, 2); // 1</code>

Parameters:

</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:


substr_count_in_byte(string $haystack, string $needle, int $offset, int|null $length): false|int

<a href="#voku-php-readme-class-methods"></a> Count the number of substring occurrences.

Parameters:

</p>` - `string $needle <p> The string being found. </p>` - `int $offset [optional] <p> The offset where to start counting </p>` - `int|null $length [optional] <p> 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. </p>`

Return:


substr_count_simple(string $str, string $substring, bool $case_sensitive, string $encoding): int

<a href="#voku-php-readme-class-methods"></a> 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:

Return:


substr_ileft(string $haystack, string $needle): string

<a href="#voku-php-readme-class-methods"></a> Removes a prefix ($needle) from the beginning of the string ($haystack), case-insensitive.

EXMAPLE: <code> UTF8::substr_ileft('ΚόσμεMiddleEnd', 'Κόσμε'); // 'MiddleEnd' UTF8::substr_ileft('ΚόσμεMiddleEnd', 'κόσμε'); // 'MiddleEnd' </code>

Parameters:

Return:


substr_in_byte(string $str, int $offset, int|null $length): false|string

<a href="#voku-php-readme-class-methods"></a> Get part of a string process in bytes.

Parameters:

Return:


substr_iright(string $haystack, string $needle): string

<a href="#voku-php-readme-class-methods"></a> Removes a suffix ($needle) from the end of the string ($haystack), case-insensitive.

EXAMPLE: <code> UTF8::substr_iright('BeginMiddleΚόσμε', 'Κόσμε'); // 'BeginMiddle' UTF8::substr_iright('BeginMiddleΚόσμε', 'κόσμε'); // 'BeginMiddle' </code>

Parameters:

Return:


substr_left(string $haystack, string $needle): string

<a href="#voku-php-readme-class-methods"></a> Removes a prefix ($needle) from the beginning of the string ($haystack).

EXAMPLE: <code> UTF8::substr_left('ΚόσμεMiddleEnd', 'Κόσμε'); // 'MiddleEnd' UTF8::substr_left('ΚόσμεMiddleEnd', 'κόσμε'); // 'ΚόσμεMiddleEnd' </code>

Parameters:

Return:


substr_replace(string|string[] $str, string|string[] $replacement, int|int[] $offset, int|int[]|null $length, string $encoding): string|string[]

<a href="#voku-php-readme-class-methods"></a> Replace text within a portion of a string.

EXAMPLE: <code>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')</code>

source: https://gist.github.com/stemar/8287074

Parameters:

</p>` - `int|int[]|null $length [optional] <p>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.</p>` - `string $encoding [optional] <p>Set the charset for e.g. "mb_" function</p>`

Return:


substr_right(string $haystack, string $needle, string $encoding): string

<a href="#voku-php-readme-class-methods"></a> Removes a suffix ($needle) from the end of the string ($haystack).

EXAMPLE: <code> UTF8::substr_right('BeginMiddleΚόσμε', 'Κόσμε'); // 'BeginMiddle' UTF8::substr_right('BeginMiddleΚόσμε', 'κόσμε'); // 'BeginMiddleΚόσμε' </code>

Parameters:

Return:


swapCase(string $str, string $encoding, bool $clean_utf8): string

<a href="#voku-php-readme-class-methods"></a> Returns a case swapped version of the string.

EXAMPLE: <code>UTF8::swapCase('déJÀ σσς iıII'); // 'DÉjà ΣΣΣ IIii'</code>

Parameters:

Return:


symfony_polyfill_used(): bool

<a href="#voku-php-readme-class-methods"></a> Checks whether symfony-polyfills are used.

Parameters: nothing

Return:


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

<a href="#voku-php-readme-class-methods"></a>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Converts the first character of each word in the string to uppercase and all other chars to lowercase.

Parameters:

Return:


to_ascii(string $str, string $unknown, bool $strict): string

<a href="#voku-php-readme-class-methods"></a> Convert a string into ASCII.

EXAMPLE: <code>UTF8::to_ascii('déjà σσς iıii'); // 'deja sss iiii'</code>

Parameters:

Return:


to_boolean(bool|float|int|string $str): bool

<a href="#voku-php-readme-class-methods"></a>

Parameters:

Return:


to_filename(string $str, bool $use_transliterate, string $fallback_char): string

<a href="#voku-php-readme-class-methods"></a> Convert given string to safe filename (and keep string case).

Parameters:

Return:


to_int(string $str): int|null

<a href="#voku-php-readme-class-methods"></a> Returns the given string as an integer, or null if the string isn't numeric.

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Convert a string into "ISO-8859"-encoding (Latin-1).

EXAMPLE: <code>UTF8::to_utf8(UTF8::to_iso8859(' -ABC-中文空白- ')); // ' -ABC-????- '</code>

Parameters:

Return:


to_string(float|int|object|string|null $input): string|null

<a href="#voku-php-readme-class-methods"></a> Returns the given input as string, or null if the input isn't int|float|string and do not implement the "__toString()" method.

Parameters:

Return:


to_utf8(string|string[] $str, bool $decode_html_entity_to_utf8): string|string[]

<a href="#voku-php-readme-class-methods"></a> This function leaves UTF-8 characters alone, while converting almost all non-UTF8 to UTF8.

<ul> <li>It decode UTF-8 codepoints and Unicode escape sequences.</li> <li>It assumes that the encoding of the original string is either WINDOWS-1252 or ISO-8859.</li> <li>WARNING: It does not remove invalid UTF-8 characters, so you maybe need to use "UTF8::clean()" for this case.</li> </ul>

EXAMPLE: <code>UTF8::to_utf8(["\u0063\u0061\u0074"]); // array('cat')</code>

Parameters:

Return:


to_utf8_string(string $str, bool $decode_html_entity_to_utf8): string

<a href="#voku-php-readme-class-methods"></a> This function leaves UTF-8 characters alone, while converting almost all non-UTF8 to UTF8.

<ul> <li>It decode UTF-8 codepoints and Unicode escape sequences.</li> <li>It assumes that the encoding of the original string is either WINDOWS-1252 or ISO-8859.</li> <li>WARNING: It does not remove invalid UTF-8 characters, so you maybe need to use "UTF8::clean()" for this case.</li> </ul>

EXAMPLE: <code>UTF8::to_utf8_string("\u0063\u0061\u0074"); // 'cat'</code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> 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: <code>UTF8::trim(' -ABC-中文空白- '); // '-ABC-中文空白-'</code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Makes string's first char uppercase.

EXAMPLE: <code>UTF8::ucfirst('ñtërnâtiônàlizætiøn foo'); // 'Ñtërnâtiônàlizætiøn foo'</code>

Parameters:

Return:


ucwords(string $str, string[] $exceptions, string $char_list, string $encoding, bool $clean_utf8): string

<a href="#voku-php-readme-class-methods"></a> Uppercase for all words in the string.

EXAMPLE: <code>UTF8::ucwords('iñt ërn âTi ônà liz æti øn'); // 'Iñt Ërn ÂTi Ônà Liz Æti Øn'</code>

Parameters:

Return:


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

<a href="#voku-php-readme-class-methods"></a> Multi decode HTML entity + fix urlencoded-win1252-chars.

EXAMPLE: <code>UTF8::urldecode('tes%20öäü%20\u00edtest+test'); // 'tes öäü ítest test'</code>

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:

Return:


utf8_decode(string $str, bool $keep_utf8_chars): string

<a href="#voku-php-readme-class-methods"></a> Decodes a UTF-8 string to ISO-8859-1.

EXAMPLE: <code>UTF8::encode('UTF-8', UTF8::utf8_decode('-ABC-中文空白-')); // '-ABC-????-'</code>

Parameters:

Return:


utf8_encode(string $str): string

<a href="#voku-php-readme-class-methods"></a> Encodes an ISO-8859-1 string to UTF-8.

EXAMPLE: <code>UTF8::utf8_decode(UTF8::utf8_encode('-ABC-中文空白-')); // '-ABC-中文空白-'</code>

Parameters:

Return:


whitespace_table(): string[]

<a href="#voku-php-readme-class-methods"></a> Returns an array with all utf8 whitespace characters.

Parameters: nothing

Return:


words_limit(string $str, int $limit, string $str_add_on): string

<a href="#voku-php-readme-class-methods"></a> Limit the number of words in a string.

EXAMPLE: <code>UTF8::words_limit('fòô bàř fòô', 2, ''); // 'fòô bàř'</code>

Parameters:

Return:


wordwrap(string $str, int $width, string $break, bool $cut): string

<a href="#voku-php-readme-class-methods"></a> Wraps a string to a given number of characters

EXAMPLE: <code>UTF8::wordwrap('Iñtërnâtiônàlizætiøn', 2, '<br>', true)); // 'Iñ<br><br>rn<br>ât<br><br><br>li<br><br>ti<br>øn'</code>

Parameters:

</p>`

Return:


wordwrap_per_line(string $str, int $width, string $break, bool $cut, bool $add_final_break, string|null $delimiter): string

<a href="#voku-php-readme-class-methods"></a> Line-Wrap the string after $limit, but split the string by "$delimiter" before ... ... so that we wrap the per line.

Parameters:

</p>` - `bool $add_final_break [optional] <p> If this flag is true, then the method will add a $break at the end of the result string. </p>` - `non-empty-string|null $delimiter [optional] <p> You can change the default behavior, where we split the string by newline. </p>`

Return:


ws(): string[]

<a href="#voku-php-readme-class-methods"></a> Returns an array of Unicode White Space characters.

Parameters: nothing

Return:


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

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