Found 1046 Articles for PHP

PHP – Get the string length using mb_strlen()

Urmila Samariya
Updated on 23-Aug-2021 08:34:29

2K+ Views

In PHP, multibyte string length (mb_strlen) function is used to get the total string length of a specified string. This function is supported in PHP 4.6.0 or higher versions.Syntaxint mb_strlen(str $string, str $encoding)Parametersmb_strlen() accepts two parameters: $string and $encoding.$string− It is used to check the string length$encoding− This parameter is used for character encoding. If it is omitted or null, then the internal character encoding value will be used.Return Valuesmb_strlen() returns the number of characters present in the given string. One is counted as a multi-byte character.Errors/ExceptionsIf the encoding is not known, then it will generate the level E_warning.Example Live DemoOutputTotal ... Read More

PHP – How to set the character encoding detection order using mb_detect_order()?

Urmila Samariya
Updated on 23-Aug-2021 08:33:52

148 Views

The mb_detect_order() function in PHP can be used to set/get the character encoding detection in an order. This function is supported in PHP 4.2.0 or higher versions.Syntaxarray|bool mb_detect_order(str $encoding)Parametersmb_detect_order() accepts only one parameter $encoding with string, array and bool.$encoding− This encoding parameter is an array or comma-separated list of character encoding. If it is omitted or null, then it returns the current character encoding detection order as an array.Return ValuesWhen setting the encoding detection order, it returns True on success or it returns False on failure.Example Live DemoOutputASCII, JIS, EUC-JPRead More

PHP – Make a lower case string using mb_strtolower()

Urmila Samariya
Updated on 23-Aug-2021 08:33:23

469 Views

In PHP, we can use the function mb_strtolower() to change a given string into lower case. It returns strings with all alphabetic characters converted to lowercase characters.Syntaxstring mb_strtolower(str $string, str $encoding)Parametersmb_strtolower() accepts two parameters: $string and $encoding.$string− The string being lowercased, returns strings with all alphabetic characters converted to lowercase characters.$encoding− This parameter is the character encoding. If it is absent or null, then the internal character encoding value will be used.Return Valuesstring with all alphabetic characters converted to lowercase.Example Live DemoOutputIt will conver all the characters in the given string to its lower case.hello world! welcome to online tutorialsRead More

PHP – Make an upper case string using mb_strtoupper()

Urmila Samariya
Updated on 23-Aug-2021 08:32:07

229 Views

In PHP, mb_strtoupper() is an inbuilt function that is used to change a given string to upper case.Syntaxstring mb_strtoupper(str $string, str $encoding)Parametersmb_strtoupper() accepts two parameters: $string and $encoding.$string− The string being uppercased.$encoding− This parameter is the character encoding. If it is absent or null, then the internal character encoding value will be used.Return Valuesstring with all alphabetic characters converted to uppercase.Example Live DemoOutputIt will convert the given string to upper case.HELLO WORLD!, WELCOME TO ONLINE TUTORIALS

PHP – How to count the number of substring using mb_substr_count()?

Urmila Samariya
Updated on 23-Aug-2021 08:30:29

146 Views

In PHP, we can use the function mb_substr_count() to count the total number of substrings in a given string.Syntaxint mb_substr_count(str $haystack, str $needle, str $encoding)Parametersmb_substr_count() accepts three parameters: $haystack, $needle and $encoding.$haystack− This parameter will check the string.$needle− This parameter will be used to tell that the substring is found from the given total string.$encoding− This parameter is the character encoding. If it is absent or null, then the internal character encoding value will be used.Return ValuesThis will return the number of times the needle substring occurs in the haystack string.Example Live DemoOutput2Read More

PHP – How to get the selected part of a string using mb_substr()?

Urmila Samariya
Updated on 23-Aug-2021 08:29:25

2K+ Views

In PHP, mb_substr() is used to return the selected part of a given string. The multibyte safe substr() works based on the number of characters. It counts the position from the starting of the string. It will return 0 for the first character position and 1 for the second position character, and so on.Syntaxstring mb_substr(str $string, int $start, int $length, str $encoding)ParametersThis PHP function accepts four parameters: $string, $start, $length and $encoding.$string− This parameter is used to extract the substring from the given string.$string = mb_substr("Welcome to the online tutorials!", 5, 10, "UTF-8");$start− This parameter returns 0 for the first ... Read More

PHP – Case folding in a string using mb_convert_case()

Urmila Samariya
Updated on 23-Aug-2021 08:28:32

345 Views

mb_convert_case() is an inbuilt function in PHP that is used to perform case folding on a given string.Syntaxstring mb_convert_case(str $string, int $mode, str $encoding)Parametersmb_convert_case() accepts three parameters: $string, $mode and $encoding to perform case folding on a string.$string− This parameter is used to return the string being converted.$mode: The mode parameter is used for the mode of the conversion. It can be used for multibyte string conversion for MB_CASE_UPPER, MB_CASE_LOWER, MB_CASE_TITLE, MB_CASE_FOLD, MB_CASE_UPPER_SIMPLE, MB_CASE_LOWER_SIMPLE, MB_CASE_TITLE_SIMPLE, MB_CASE_FOLD_SIMPLE.$encoding: This parameter is the character encoding. If it is omitted or null, then the internal character encoding value will be usedReturn Valuesmb_convert_case() is used to return ... Read More

PHP – How to return character by Unicode code point value using mb_chr()?

Urmila Samariya
Updated on 23-Aug-2021 08:27:39

675 Views

In PHP, the mb_chr() function is used to return character by Unicode code point value. This function returns a string having the character identified by the Unicode code point value, encoded in the specified encoding.Syntaxstring mb_chr(int $codepoint, string $encoding)Parametersmb_chr() accepts only two parameters: $codepoint and $encoding.$codepoint− This parameter is used to convert a Unicode codepoint value. For example, 128024 for U+1F418 ELEPHANT.$encoding− This parameter is the character encoding. If it is absent or null, then the internal character encoding value will be used.Return ValuesThis function returns a string containing the requested character if it can be represented in the specified encoding ... Read More

PHP – Check if strings are valid for the specified encoding using mb_check_encoding()

Urmila Samariya
Updated on 23-Aug-2021 08:27:00

761 Views

In PHP, the mb_check_encoding() function is used to check if the given strings are valid for the specified encoding. This function checks if the specified byte stream is valid for the specified encoding.Syntaxbool mb_check_encoding(str $value=null, str $encoding=null)Note: The function will check if the stated byte stream is valid for the stated encoding. And if the given value is an array type, then all the keys and values will validate recursively. It avoids the invalid encoding attack.Parametersmb_check_encoding() accepts two parameters: $value and $encoding.$value− It is used to check the byte stream or array if it is omitted and it checks all ... Read More

PHP – Convert a string to a requested character encoding using iconv()

Urmila Samariya
Updated on 23-Aug-2021 08:25:44

899 Views

In PHP, the iconv() function is used to convert a string to the requested character encoding. It is used to perform a character set conversion on the string "string" from from_encoding to to_encoding.Syntaxstring iconv(str $from_encoding, str $to_encoding, str $string)ParametersThe iconv() function accepts three parameters: $from_encoding, $to_encoding and $string.$from_encoding− This parameter is used to specify the input charset.$to_encoding− This parameter is used for the output charset.$string− This parameter is used to convert the string.Return Valuesiconv() returns the converted string on success or it returns False on failure.Example Live Demo     OutputOriginal:the Dollar symbol '$' TRANSLIT: the Dollar symbol '$' IGNORE: the Dollar symbol ... Read More

Advertisements