wp_sprintf [ WordPress Function ]
wp_sprintf ( $pattern )
| Parameters: |
|
| Links: | |
| Returns: |
|
| 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) - 1 == $start ) {
$result .= substr($pattern, -1);
break;
}
// Literal %: append and continue
if ( substr($pattern, $start, 2) == '%%' ) {
$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($fragment, strval($arg) );
}
// Append to result and move to next fragment
$result .= $fragment;
$start = $end;
}
return $result;
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- WordPress code surprise: wp_sprintf | Andy Skelton
Jan 5, 2011 ... I wrote wp_sprintf() as a wrapper for sprintf() . It uses WordPress filters to customize the formatting directives. WordPress only uses this in one ...
andy.wordpress.com - wp_sprintf() WordPress function reference, arguments and source at ...
WordPress implementation of PHP sprintf() with filters.
queryposts.com - wp_sprintf Wordpress hook details -- Adam Brown, BYU Political ...
Detailed information about every action hook and filter used in WordPress. Makes Plugin API easier to use. Lists appearance, file location, and deprecation data ...
adambrown.info - wp_sprintf (WordPress Function) - WPSeek.com
WordPress lookup for wp_sprintf, a WordPress Function. wpseek.com is a WordPress-centric search tool for developers and theme authors.
wpseek.com