str_pad() function will pad a string to a certain length with another string.
This will return a padded string.
<?php $strExample = "Hi from tutorialmines."; echo str_pad($strExample,30,"!"); ?>
In above example ,We have a string “Hi from tutorialmines.”. Now this function will pad the string “!” in the right side of string and makes its length to 30. Output of above code in the browser is as below:
<?php $strExample = "Hi from tutorialmines."; echo str_pad($strExample,30,"!",STR_PAD_LEFT); ?>
In above example ,We have a string “Hi from tutorialmines.”. Now this function will pad the string “!” in the LEFT side of string and makes its length to 30. Output of above code in the browser is as below:
<?php $strExample = "Hi from tutorialmines."; echo str_pad($strExample,30,"!",STR_PAD_BOTH); ?>
In above example ,We have a string “Hi from tutorialmines.”. Now this function will pad the string “!” in the LEFT and RIGHT both side of string and makes its length to 30. Output of above code in the browser is as below:
!!!!Hi from tutorialmines.!!!!
<?php $strExample = "Hi from tutorialmines."; echo str_pad($strExample,20,"!"); ?>
In above example ,We have a string “Hi from tutorialmines.”. Now str_pad() length values is less than the length of input string. So, nothing will be padded and the inpu string will be returned. Output of above code in the browser is as below:
Hi from tutorialmines.
When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…
In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…
In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…
In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…
When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…
In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…