Switch language

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




wp_sprintf [ WordPress Function ]

wp_sprintf ( $pattern )
Parameters:
  • (string) $pattern The string which formatted args are inserted.
  • (mixed) $args,... Arguments to be formatted into the $pattern string.
Links:
Returns:
  • (string) The formatted string.
Defined at:



WordPress implementation of PHP sprintf() with filters.

Source


<?php
function wp_sprintf$pattern ) {
    
$args func_get_args( );
    
$len strlen($pattern);
    
$start 0;
    
$result '';
    
$arg_index 0;
    while ( 
$len $start ) {
        
// Last character: append and break
        
if ( strlen($pattern) - == $start ) {
            
$result .= substr($pattern, -1);
            break;
        }

        
// Literal %: append and continue
        
if ( substr($pattern$start2) == '%%' ) {
            
$start += 2;
            
$result .= '%';
            continue;
        }

        
// Get fragment before next %
        
$end strpos($pattern'%'$start 1);
        if ( 
false === $end )
            
$end $len;
        
$fragment substr($pattern$start$end $start);

        
// Fragment has a specifier
        
if ( $pattern[$start] == '%' ) {
            
// Find numbered arguments or take the next one in order
            
if ( preg_match('/^%(\d+)\$/'$fragment$matches) ) {
                
$arg = isset($args[$matches[1]]) ? $args[$matches[1]] : '';
                
$fragment str_replace("%{$matches[1]}$"'%'$fragment);
            } else {
                ++
$arg_index;
                
$arg = isset($args[$arg_index]) ? $args[$arg_index] : '';
            }

            
// Apply filters OR sprintf
            
$_fragment apply_filters'wp_sprintf'$fragment$arg );
            if ( 
$_fragment != $fragment )
                
$fragment $_fragment;
            else
                
$fragment sprintf($fragmentstrval($arg) );
        }

        
// Append to result and move to next fragment
        
$result .= $fragment;
        
$start $end;
    }
    return 
$result;
}
?>

Examples [ wp-snippets.com ]

Google Arama Sonuçlarý

Dahasý ...

Kullanýcý Tartýþmalarý [ wordpress.org ]

- Bulunamadý -

Yeni bir konu yaz ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



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