Using sprintf to right justify a string
Posted: Tue Aug 25, 2009 9:09 pm
Hi all,
I am having problems getting the sprintf to work correctly with left and right formatting
For example my string is 16 characters "Yellow Submarine"
1) What I want to display is "low Submarine" using sprintf formatting and I do not seem to be able to do it.
My code so far......
the output from the code is:
Format [%-13.13s] = [Yellow Submar]
Can someone please help me to right justify it?
Thanks.
I am having problems getting the sprintf to work correctly with left and right formatting
For example my string is 16 characters "Yellow Submarine"
1) What I want to display is "low Submarine" using sprintf formatting and I do not seem to be able to do it.
My code so far......
Code: Select all
$str = "Yellow Submarine";
$fmt = "%-13.13s"; // attempt at right-justification but with a cutoff of 13 characters
echo "<BR>Format [".htmlentities($fmt)."] = ".sprintf('['.$fmt.']',$str);
Format [%-13.13s] = [Yellow Submar]
Can someone please help me to right justify it?
Thanks.