Saturday, November 22, 2025
HomeLanguagesPHP mb_check_encoding() Function

PHP mb_check_encoding() Function

The mb_check_encoding() function is an inbuilt function in PHP that is used to check whether a given string is valid for specified encoding or not.

Syntax:

bool mb_check_encoding(
    array|string|null $value = null, 
    string $encoding = null
)

Parameters: This function accepts two parameters that are described below:

  • $value: This parameter accepts the byte stream or array to check. If this value is null then it checks for all input from the beginning to the request.
  • $encoding: This parameter accepts the expected encoding.

Return Value: This function returns “true” on success and “false” on Failure.

Note: 

  • The value of $value and $encoding parameters are null in version 8.0.0.
  • This function now accepts an array of values and formally it accepts only string values.

Example 1:  The following code demonstrates the PHP mb_check_encoding() method.

PHP




<?php
  
    // Declare a variable and assign
    // string value
    $str = "Welcome to neveropen";
  
    // Check string for specified encoding
    $bool = mb_check_encoding($str, "ASCII");
  
    // Returns true means string is
    // valid for specified encoding
    var_dump($bool);
  
?>


Output

bool(true)

Example 2: The following code demonstrates another example for the PHP mb_check_encoding() method.

PHP




<?php
  
    // Declare a variable and assign
    // string value
    $str = "Welcome to neveropen";
  
    // Check string for base64 encoding
    $bool = mb_check_encoding($str, "base64");
  
    // Returns true means string is
    // valid for specified encoding
    var_dump($bool);
  
?>


Output

bool(false)

Reference: https://www.php.net/manual/en/function.mb-check-encoding.php

RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11931 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6848 POSTS0 COMMENTS