Pad a string to a certain length with another string.
Syntax:- str_pad (input, pad_length, pad_string_value, pad_type) It returns the padded string.
input:-The input string.
pad_length:-If the value of pad_length is negative, less than, or equal to the length of the input string, no padding takes place, and input is returned.
pad_string_input:-The pad_string may be truncated if the required number of padding characters can’t be evenly divided by the pad_string’s length.
pad_type:-Optional argument pad_type can be STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH. If pad_type is not specified it is assumed to be STR_PAD_RIGHT.
Print simple patterns like below using single line of code under loop.
Input : 5 Output : * ** *** **** ***** Input : 6 Output : * ** *** **** ***** ******
* ** *** **** ***** ******
- How to use SVG Patterns as the background ?
- Difference between MVC and MVT design patterns
- Asynchronous Patterns in Node.js
- Django URL patterns | Python
- Principles and Patterns of User Interface Design
- Function to escape regex patterns before applied in PHP
- PHP | Program to check a string is a rotation of another string
- What is the difference between 'String' and 'string' in TypeScript ?
- p5.js | print() function
- PHP | echo and print
- How to print all the values of an array in PHP ?
- Print PHP Call Stack
- What is stacktrace and how to print in node.js ?
- How to add innerHTML to print page?
- What is the difference between echo, print, and print_r in PHP?
- How to print variable to the terminal in SASS ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.