PHP Articles

Page 16 of 81

PHP – Encode string for MIME header using mb_encode_mimeheader()

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 643 Views

In PHP, mb_encode_mimeheader() function is used to encode a string for MIME (Multipurpose Internet Mail Extensions) header. It encodes a given string by the MIME header encoding scheme, which is essential for email headers containing non-ASCII characters. Syntax string mb_encode_mimeheader( string $string, ?string $charset = null, ?string $transfer_encoding = null, string $newLine = "\r", int $indent = 0 ) Parameters The mb_encode_mimeheader() function accepts five parameters − $string − The string to ...

Read More

PHP – How to detect character encoding using mb_detect_encoding()

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 7K+ Views

In PHP, mb_detect_encoding() is used to detect the character encoding of a string from an ordered list of candidates. This function is particularly useful when working with multibyte encodings where not all byte sequences form valid strings. If the input contains invalid sequences for a particular encoding, that encoding is rejected and the next one is tested. Syntax string mb_detect_encoding(string $string, array|string|null $encoding_list = null, bool $strict = false) Note: Character encoding detection is not entirely reliable without additional context. It's similar to decoding encrypted data without a key. A Content-Type HTTP header can provide ...

Read More

PHP – How to get the substitution character using mb_substitute_character()?

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 355 Views

In PHP, we can use the function mb_substitute_character() to get or set the substitution character. This function specifies the substitution character when the input character encoding is not valid or the character code does not exist in the output character encoding. Note: The invalid characters may be substituted with no output, string, or int value (Unicode character code value). Syntax string mb_substitute_character($char) Parameters This function accepts only one parameter, $char. $char − It specifies the Unicode value as an integer or the strings given below: "none" − It will return ...

Read More

PHP – Make a lower case string using mb_strtolower()

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 580 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, with proper support for multibyte character encodings. Syntax string mb_strtolower(string $string, ?string $encoding = null) Parameters mb_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 ...

Read More

PHP – Make an upper case string using mb_strtoupper()

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 378 Views

In PHP, mb_strtoupper() is a multibyte string function that converts all alphabetic characters in a string to uppercase. Unlike the regular strtoupper() function, it properly handles multibyte characters and various character encodings. Syntax string mb_strtoupper(string $string, ?string $encoding = null) Parameters mb_strtoupper() accepts two parameters: $string and $encoding. $string− The string being converted to uppercase. $encoding− The character encoding. If omitted or null, the internal character encoding value will be used. Return Value Returns a string with all alphabetic characters converted to uppercase. Example Here's how to ...

Read More

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

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 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. Syntax string mb_substr(str $string, int $start, int $length, str $encoding) Parameters This PHP function accepts four parameters: $string, $start, $length and $encoding. $string − This parameter is used to extract the substring from the ...

Read More

PHP – Case folding in a string using mb_convert_case()

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 545 Views

The mb_convert_case() function is an inbuilt PHP function used to perform case folding on a given string. It supports multibyte character encodings and offers various conversion modes for different case transformations. Syntax string mb_convert_case(string $string, int $mode, ?string $encoding = null) Parameters The mb_convert_case() function accepts three parameters ? $string − The input string to be converted. $mode − The conversion mode. Available constants include: MB_CASE_UPPER − Convert to uppercase MB_CASE_LOWER − Convert to lowercase MB_CASE_TITLE − Convert to title case MB_CASE_FOLD − Case folding (PHP 7.3+) MB_CASE_UPPER_SIMPLE − Simple uppercase ...

Read More

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

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 901 Views

In PHP, the mb_chr() function is used to return a character by Unicode code point value. This function returns a string containing the character identified by the Unicode code point value, encoded in the specified encoding. Syntax string mb_chr(int $codepoint, string $encoding) Parameters mb_chr() accepts two parameters: $codepoint and $encoding. $codepoint − The Unicode code point value to convert. For example, 128024 for U+1F418 ELEPHANT. $encoding − The character encoding. If omitted or null, the internal character encoding value will be used. ...

Read More

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

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 1K+ Views

In PHP, the mb_check_encoding() function is used to check if the given strings are valid for the specified encoding. This function validates whether the specified byte stream conforms to the stated encoding rules. Syntax bool mb_check_encoding(string $value = null, string $encoding = null) Parameters mb_check_encoding() accepts two parameters: $value − The byte stream, string, or array to check. If omitted, it checks all input from the beginning of the request. $encoding − The expected encoding. If omitted, it uses the internal encoding. Return Value mb_check_encoding() returns true if the ...

Read More

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

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 1K+ Views

In PHP, the iconv() function is used to convert a string from one character encoding to another. It performs character set conversion on the string from a source encoding to a target encoding, making it essential for handling multilingual text and ensuring proper character display across different systems. Syntax string iconv(string $from_encoding, string $to_encoding, string $string) Parameters The iconv() function accepts three parameters: $from_encoding − The input charset (source encoding) $to_encoding − The output charset (target encoding). You can append //TRANSLIT or //IGNORE for special handling $string − The string to be ...

Read More
Showing 151–160 of 802 articles
« Prev 1 14 15 16 17 18 81 Next »
Advertisements