Horje
PHP mb_scrub() Function

The mb_scrub() is an inbuilt PHP function that replaces an invalid character set to the substitute character. If the encoding is not provided. It will use default encoding.

Syntax:

mb_scrub($string, $encoding );

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

  • $string: The input string that you want to scrub, replaces invalid or unmatched surrogate sequences.
  • $encoding: This is the optional parameter. It defines the encoding for replacing the characters set. If encoding is not defined. It will use default encoding.

Return value: The mb_scrub() function returns the string which is replaced with an invalid byte sequence

Program 1: The following program demonstrates the mb_scrub() function.  In the below program. The string is already valid so the string returned as it is.

PHP

<?php
    
$inputString = "Hello World!";
$output = mb_scrub($inputString, "UTF-8");
echo $output;
  
?>

Output

Hello World!

Program 2: The following program demonstrates the mb_scrub() function.In the below program. The string is not valid so this function changes the string according to the default encoding.

PHP

<?php
$inputString = "H\xC3\xA9llo W\xf2rld!";
$scrubbedString = mb_scrub($inputString);
echo $scrubbedString;
?>

Output

Héllo W?rld!

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




Reffered: https://www.geeksforgeeks.org


PHP

Related
PHP readline() Function PHP readline() Function
PHP openssl_pbkdf2() Function PHP openssl_pbkdf2() Function
PHP mb_encode_numericentity() Function PHP mb_encode_numericentity() Function
PHP 7 Closure call( ) Method PHP 7 Closure call( ) Method
Explain Controls in CherryFramework Explain Controls in CherryFramework

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
13