Str_pad function

Str_pad function

Syntax:

string str_pad ( string input, int pad_length [, string pad_string [, int pad_type]])

str_pad function is used to pad a string to specific length with another string.

Example:

<?php

$username = “sampleuser”;

echo str_pad($username,18,’*',STR_PAD_BOTH);

?>

In above example, First parameter $username is input string. Second parameter 18 is pad length. Third parameter * is the pad string which is optional. Default pad string is space. Fourth parameter STR_PAD_BOTH is pad type which will pad string on both sides. Default pad type is STR_PAD_RIGHT.

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.