Jump to content

pad the string with a character


Omzy

Recommended Posts

Any, why won't string_pad() work? It works fine for me:

 

<?php

$text   = "My Text";

echo str_pad($text, 10, "|"); //Output: My Text|||
echo str_pad($text, 10, "|", STR_PAD_LEFT); //Output: |||My Text
echo str_pad($text, 10, "|", STR_PAD_BOTH); //Output: |My Text||

?>

 

Of course, you can also use printf()/sprintf()

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.