esc_url [ WordPress Function ]
esc_url ( $url, $protocols = null, $_context = 'display' )
| Parameters: |
|
| Uses: | |
| Returns: |
|
| Defined at: |
|
Checks and cleans a URL.
A number of characters are removed from the URL. If the URL is for displaying (the default behaviour) ampersands are also replaced. The 'clean_url' filter is applied to the returned cleaned URL.
Source
<?php
function esc_url( $url, $protocols = null, $_context = 'display' ) {
$original_url = $url;
if ( '' == $url )
return $url;
$url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i', '', $url);
$strip = array('%0d', '%0a', '%0D', '%0A');
$url = _deep_replace($strip, $url);
$url = str_replace(';//', '://', $url);
/* If the URL doesn't appear to contain a scheme, we
* presume it needs http:// appended (unless a relative
* link starting with /, # or ? or a php file).
*/
if ( strpos($url, ':') === false && ! in_array( $url[0], array( '/', '#', '?' ) ) &&
! preg_match('/^[a-z0-9-]+?\.php/i', $url) )
$url = 'http://' . $url;
// Replace ampersands and single quotes only when displaying.
if ( 'display' == $_context ) {
$url = wp_kses_normalize_entities( $url );
$url = str_replace( '&', '&', $url );
$url = str_replace( "'", ''', $url );
}
if ( ! is_array( $protocols ) )
$protocols = wp_allowed_protocols();
if ( wp_kses_bad_protocol( $url, $protocols ) != $url )
return '';
return apply_filters('clean_url', $url, $original_url, $_context);
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- Function Reference/esc url « WordPress Codex
Always use esc_url when sanitizing URLs (in text nodes, attribute nodes or anywhere else). Rejects URLs that do not have one of the provided whitelisted ...
codex.wordpress.org - clean_url() vs. sanitize_url() vs. esc_url() vs ... - WordPress
(2 posts). Trahald Member Posted 2 years ago #. I believe that in 2.8, clean_url() and sanitize_url() were deprecated in favor of esc_url() and esc_url_raw().
wordpress.org - Data Validation « WordPress Codex
esc_url( $url, (array) $protocols = null ) (since 2.8): Always use esc_url when sanitizing URLs (in text nodes, attribute nodes or anywhere else). Rejects URLs ...
codex.wordpress.org - esc_url removes white space. Can I change that to using '-'?
Apr 7, 2011 ... I'm using esc_url to sanitize my url. The only problem is that "my link" becomes " mylink". I wouldreally like it to become "my-link". Is there a way ...
wordpress.stackexchange.com