mb_scrub() 是一個內置 PHP 函數,用於將無效字符集替換為替換字符。如果未提供編碼。它將使用默認編碼。
用法:
mb_scrub($string, $encoding );
Parameters: 該函數接受兩個參數,如下所述。
- $string: 您要清理的輸入字符串將替換無效或不匹配的代理序列。
 - $encoding: 這是可選參數。它定義了用於替換字符集的編碼。如果未定義編碼。它將使用默認編碼。
 
返回值: mb_scrub()函數返回被無效字節序列替換的字符串
程序1:下麵的程序演示了mb_scrub()函數。在下麵的程序中。該字符串已經有效,因此字符串按原樣返回。
PHP
<?php 
    
$inputString = "Hello World!"; 
$output = mb_scrub($inputString, "UTF-8"); 
echo $output; 
  
?>輸出
Hello World!
程序2:下麵的程序演示了mb_scrub()函數。在下麵的程序中。該字符串無效,因此該函數根據默認編碼更改字符串。
PHP
<?php 
$inputString = "H\xC3\xA9llo W\xf2rld!"; 
$scrubbedString = mb_scrub($inputString); 
echo $scrubbedString; 
?>輸出
Héllo W?rld!
參考: https://www.php.net/manual/en/function.mb-scrub.php
相關用法
- PHP mb_strlen()用法及代碼示例
 - PHP mb_substr_count()用法及代碼示例
 - PHP mb_substr()用法及代碼示例
 - PHP mb_substitute_character()用法及代碼示例
 - PHP mb_strtolower()用法及代碼示例
 - PHP mb_strtoupper()用法及代碼示例
 - PHP mb_str_split()用法及代碼示例
 - PHP mb_strrchr()用法及代碼示例
 - PHP mb_strimwidth()用法及代碼示例
 - PHP mb_stristr()用法及代碼示例
 - PHP mb_split()用法及代碼示例
 - PHP mb_strripos()用法及代碼示例
 - PHP mb_strstr()用法及代碼示例
 - PHP mb_strpos()用法及代碼示例
 - PHP mb_stripos()用法及代碼示例
 - PHP mb_strrichr()用法及代碼示例
 - PHP mb_strcut()用法及代碼示例
 - PHP mb_convert_case()用法及代碼示例
 - PHP mb_check_encoding()用法及代碼示例
 - PHP mb_chr()用法及代碼示例
 - PHP mb_detect_order()用法及代碼示例
 - PHP mb_ereg()用法及代碼示例
 - PHP mb_http_input()用法及代碼示例
 - PHP mb_convert_encoding()用法及代碼示例
 - PHP mb_parse_str()用法及代碼示例
 
注:本文由純淨天空篩選整理自neeraj3304大神的英文原創作品 PHP mb_scrub() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
