This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.
23 05, 2009

str_pad

By | 2009-05-20T13:27:13+00:00 May 23rd, 2009|Categories: PHP, Ruby|Tags: , , , , |Comments Off on str_pad

str_pad allows a string to be added to a particular length using another string.

PHP

echo str_pad('Hi', 5);
// => 'Hi   '

echo str_pad('Hi', 5, '+');
// => 'Hi+++'

echo str_pad('78', 5, '0', STR_PAD_LEFT);
// => '00078'

Instead of padding a string, in Ruby we justify a string to the left or right.

Ruby

puts "Hi".ljust(5);
# => 'Hi   '

puts "Hi".ljust(5, '+');
# => 'Hi+++'

puts "78".rjust(5, '0');
# => '00078'

To pad both sides of a string, we need to use a combination of ljust and rjust.

PHP

echo str_pad('Special', 11, '*', STR_PAD_BOTH);
// => '**Special**'

Ruby

puts "Special".ljust(9).rjust(11);
# => '**Special**'