Result Size: 625 x 571
x
 
<!DOCTYPE html>
<html>
<body>
<?php
$str1 = 'Hello';
$str2 = 'Hello world!';
echo sprintf("[%s]",$str1)."<br>"; // String
echo sprintf("[%8s]",$str1)."<br>"; // Right-justifies the string with spaces
echo sprintf("[%-8s]",$str1)."<br>"; // Left-justifies the string with spaces
echo sprintf("[%08s]",$str1)."<br>"; // Zero-padding
echo sprintf("[%'*8s]",$str1)."<br>"; // Adds "*"
echo sprintf("[%8.8s]",$str2)."<br>"; // Left-justifies the string with spaces (cuts off characters after the specified value)
?> 
</body>
<!-- Mirrored from www.w3schools.com/php/phptryit.asp?filename=tryphp_func_string_sprintf5 by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Jan 2020 02:51:06 GMT -->
</html>
×

Report a Problem: