関数 wp_sprintf()
2014/12/11
関数 wp_sprintf()
定義ファイル :/blog/wp-includes/formatting.php 11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 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] : ''; } $_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; } |