Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
function mb_str_pad( $input, $pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT) {
$diff = strlen( $input ) - mb_strlen( $input );
return str_pad( $input, $pad_length + $diff, $pad_string, $pad_type );
}
// assign data to variables
$games = [
'football',
'футбол', // football in russian
'ფეხბურთი', // football in georgian
'хөл бөмбөг', // football in mongolian
'bóng đá' // football in vietnamese
];
// loop through $games array and print rows with built-in str_pad function
foreach ($games as $game) {
echo str_pad($game, 20) . '|' . PHP_EOL;
}
echo PHP_EOL . PHP_EOL;
// loop through $games array and print rows with custom mb_str_pad function
foreach ($games as $game) {
echo mb_str_pad($game, 20) . '|' . PHP_EOL;
}