Codex tools: Log in
Sanitizes title or use fallback title.
Specifically, HTML and PHP tags are stripped, and (in a 'save' context) accents are removed (accented characters are replaced with non-accented equivalents). Further filtering can be added via the plugin API by hooking the sanitize_title filter. If
$title is empty and
$fallback_title is set, the latter will be used.
Despite the name of this function, the returned value is intended to be suitable for use in a URL, not as a human-readable title.
<?php sanitize_title( $title, $fallback_title, $context ) ?>
To create the file name portion of a URL the same way that WordPress does use this:
<?php $new_url = sanitize_title('This Long Title is what My Post or Page might be'); echo $new_url; ?>
It should return a formatted value, the output would be this:
The 'save' context is used most often when saving a value in the database, but is used for other purposes as well. The 'query' context is used by sanitize_title_for_query() when the value is going to be used in the
WHERE clause of a query.
$contextparameter added in 3.1
sanitize_title() is located in
sanitize_title() is in a class of functions that help you sanitize potentially unsafe data which allow you to pass an arbitrary variable and receive the clean version based on data type. Others include: