How to Add Padding to String PHP?

String padding is a great solution for the specific problem of adding padding to a string. It comes in several flavors that allow it to be used in multiple different scenarios. However, like all developers, sometimes we need to think outside the box to get the job done. String padding is a fantastic tool in our PHP builder belt, but we should remember there may be easier solutions in some cases.

php 0 padding left

on Jan 01, 1970
<?php
$input = "Alien";
echo str_pad($input, 10);                      // produces "Alien     "
echo str_pad($input, 10, "-=", STR_PAD_LEFT);  // produces "-=-=-Alien"
echo str_pad($input, 10, "_", STR_PAD_BOTH);   // produces "__Alien___"
echo str_pad($input,  6, "___");               // produces "Alien_"
echo str_pad($input,  3, "*");                 // produces "Alien"
?>

Add Comment

0

php str_pad not working

on Jan 01, 1970
str_pad($myString, 9, '0', STR_PAD_LEFT);
// "000024896"

Add Comment

0

The PHP function string_pad() pads a string on the left, right, or both sides with zeros and/or spaces. You can use this function to pad the values your app outputs.

PHP answers related to "str_pad_left in php"

View All PHP queries

PHP queries related to "str_pad_left in php"

str_pad_left in php ?? ' ' operator in php laravel php artisan app:name in laravel 6 php artisan make:auth laravel 8 not working php artisan ui:auth laravel 7 php cache clear in laravel php extensions for laravel php laravel dump php laravel return json response php laravel rount price to 99 php run server laravel php unit testing laravel remove index.php laravel in linux server cheque print in php codeigniter install php ubuntu 20.04 php enable module php display errors php console log php for loop php sha256 php in array php uppercase each word php uppercase first letter php is numeric php now simple localhost php php include once inside a function? php if else how to convert array to string with commas in php curl php example php string to date php string functions Line : 83 -- syntax error, unexpected end of file php php file_put_contents pagination in php php print_r php check if type is mysqli_result saber value ao escolher combobox php Best Code Beautifier tools for php Uncaught TypeError: Argument 1 passed to NotORM_Result::update() php slim array shift php php PDO database connection set default php version in ubuntu php time() spread operator php Check if string starts with php radio button in php form increase PHP Memory login.php php class https//:localhost/phpmyadmin/index.php php get session variable from table Convert string to lowercase in php parseint php Php array length date to string php php reverse shell Mkdir permission denied php Php += Move uploaded file in php Php mysqli fetch assoc Php trying to get property of non-object Php strtolower date format in php array to object in php Send email php smtp hostinger Show all errors in php binemon to php password and confirm password validation in php php int to strin php timeout Php localhost php htmlspecialchars php redirect to page

Browse Other Code Languages

CodeProZone