Monthly Archive: October 2010
String .prototype .format = function ( ) {
var a = arguments;
return this .replace ( /\{\d+\}/g , function ( c) {
return a[ c.match ( /\d+/ ) ] ;
} ) ;
}
// usage:
var str = 'Hello, {0}! You are {1}!' ;
str.format ( 'friend' , 'awesome' ) ;
// Hello, friend! You are awesome!
String.prototype.format = function() {
var a = arguments;
return this.replace(/\{\d+\}/g, function©{
return a[c.match(/\d+/)];
});
}
// usage:
var str = ‘Hello, {0}! You are {1}!’;
str.format(‘friend’, ‘awesome’);
// Hello, friend! You are awesome!
P.S.: Вот как-то так :D
function bytes( $s ) {
$units = 'KMGT' ;
return pow ( 1024 , strpos ( $units , strpbrk ( $s , $units ) ) + 1 ) * ( int) $s ;
}
// usage:
echo bytes( '1K' ) ; // 1024
echo bytes( '1M' ) ; // 1048576
function bytes($s) {
$units = ‘KMGT’;
return pow(1024, strpos($units, strpbrk($s, $units)) + 1) * (int) $s;
}
// usage:
echo bytes(‘1K’); // 1024
echo bytes(‘1M’); // 1048576
VIDEO
Vamos a bailar — Esta vida Nueva
( Paola & Chiara — Vamos A Bailar )
(more…)