Programming Articles

Page 1015 of 2547

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 367 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

How will you print numbers from 1 to 100 without using loop in C?

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 15-Mar-2026 4K+ Views

You can print numbers from 1 to 100 without using traditional loops by employing alternative control structures like recursive functions and goto statements. These methods achieve the same repetitive behavior through different mechanisms. Method 1: Using Recursion Recursion allows a function to call itself repeatedly until a base condition is met. We can use this property to print numbers sequentially without explicit loops − #include void printNumbers(int n) { if (n > 100) return; printf("%d ", n); ...

Read More

PHP – Make a lower case string using mb_strtolower()

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 602 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 407 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 576 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

Difference between strlen() and sizeof() for string in C

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 1K+ Views

In C programming, strlen() and sizeof() are commonly used to work with strings, but they serve different purposes and return different values. Understanding their differences is crucial for effective string manipulation. strlen() Function The strlen() function is declared in string.h header file and calculates the actual length of a string by counting characters until it encounters the null terminator '\0'. Syntax size_t strlen(const char *string); string − The string whose length is to be calculated. Example #include #include int main() { char s1[10] ...

Read More

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

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 928 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
Showing 10141–10150 of 25,466 articles
Advertisements