Open In App

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:

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



Note: 

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




<?php
  
    // Declare a variable and assign
    // string value
    $str = "Welcome to GeeksforGeeks";
  
    // 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
  
    // Declare a variable and assign
    // string value
    $str = "Welcome to GeeksforGeeks";
  
    // 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


Article Tags :