WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp check invalid utf8

This page is marked as incomplete. You can help Codex by expanding it.

Description

Checks for invalid UTF8 in a string. This can be one step in sanitizing input data. For complete sanitizing, including checking for valid UTF8, use one of the sanitize_*() functions.

Usage

<?php $string wp_check_invalid_utf8$string$strip ); ?>

Parameters

$string
(string) (required) the string to be checked
Default: None
$strip
(boolean) (optional) strip out invalid chars?
Default: false

Return Value

(string) 
The checked string, optionally with invalid chars stripped. Empty string is returned if passed string value is invalid UTF8

Examples

<?php $string = wp_check_invalid_utf8( $_POST['description'], true ); 
if ( '' == $string ) die('Your description text used an invalid charset, it must be UTF8'); ?>

Notes

The source code comments suggest that actually stripping invalid characters is not recommended. Uses the PHP iconv module which may not be available on some installations.

Change Log

Since: 2.8.0

Source File

Related

 

See also index of Function Reference and index of Template Tags.