Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




esc_url [ WordPress Function ]

esc_url ( $url, $protocols = null, $_context = 'display' )
Parameters:
  • (string) $url The URL to be cleaned.
  • (array) $protocols Optional. An array of acceptable protocols. Defaults to 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn' if not set.
  • (string) $_context Private. Use esc_url_raw() for database usage.
Uses:
Returns:
  • (string) The cleaned $url after the 'clean_url' filter is applied.
Defined at:

Benzer Fonksiyonlar: esc_url_raw, esc_sql, esc_html, home_url, esc_attr


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'&amp;''&#038;'$url );
        
$url str_replace"'"'&#039;'$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ý

Dahasý ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics