Attention 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.


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.


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


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

Return Value

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


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


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



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