Name

LPAD()

Synopsis

LPAD(str, len, padstr)

Returns the string str padded to a length of len characters by prepending the string with padstr characters. If str is longer than len then the string returned will be truncated to len characters. The example code returns the following strings:

January
February
   March
   April
     May

Notice how all the strings have been padded to be eight characters long.

SELECT LPAD('January', '8', ' ');
SELECT LPAD('February', '8', ' ');
SELECT LPAD('March', '8', ' ');
SELECT LPAD('April', '8', ' ');
SELECT LPAD('May', '8', ' ');

Get Learning PHP, MySQL, and JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.