PKPString::utf8_bad_strip PHP Method

utf8_bad_strip() static public method

Strips out any bad bytes from a UTF-8 string and returns the rest
static public utf8_bad_strip ( $str ) : string
$str string input string
return string
    static function utf8_bad_strip($str)
    {
        require_once './lib/pkp/lib/phputf8/utils/bad.php';
        return utf8_bad_strip($str);
    }

Usage Example

 /**
  * Sanitize a variable.
  * Removes leading and trailing whitespace, normalizes all characters to UTF-8.
  * @param $var string
  * @return string
  */
 static function cleanVar($var)
 {
     // only normalize strings that are not UTF-8 already, and when the system is using UTF-8
     if (Config::getVar('i18n', 'charset_normalization') == 'On' && strtolower_codesafe(Config::getVar('i18n', 'client_charset')) == 'utf-8' && !PKPString::utf8_is_valid($var)) {
         $var = PKPString::utf8_normalize($var);
         // convert HTML entities into valid UTF-8 characters (do not transcode)
         $var = html_entity_decode($var, ENT_COMPAT, 'UTF-8');
         // strip any invalid UTF-8 sequences
         $var = PKPString::utf8_bad_strip($var);
         $var = htmlspecialchars($var, ENT_NOQUOTES, 'UTF-8', false);
     }
     // strip any invalid ASCII control characters
     $var = PKPString::utf8_strip_ascii_ctrl($var);
     return trim($var);
 }
All Usage Examples Of PKPString::utf8_bad_strip