xiaix Posted August 26, 2009 Share Posted August 26, 2009 This code: if ($data1["e"] > 0) { $part .= sprintf("<strong>%s %d %s</strong>", $data1["e"] > 0 ? "+":"-", $data1["e"], $defType["e"]); if ($howManyArmorDef > ($e1 += 1)) { $part .= "<BR />"; }} Displays this: +54 Melee Piercing Defense Fine, but if I use this code (notice the %5s): if ($data1["e"] > 0) { $part .= sprintf("<strong>%s %d %5s</strong>", $data1["e"] > 0 ? "+":"-", $data1["e"], $defType["e"]); if ($howManyArmorDef > ($e1 += 1)) { $part .= "<BR />"; }} I still get this: +54 Melee Piercing Defense But I should get this: +54 Melee Piercing Defense What gives? What am I doing wrong? Thanks. Link to comment https://forums.phpfreaks.com/topic/171967-solved-sprintf-variable-padding/ Share on other sites More sharing options...
ignace Posted August 26, 2009 Share Posted August 26, 2009 the padding is there however HTML does not show padding in order to display it either wrap it in pre or code tags or assign an id or class to the element and via CSS add the line: white-space: pre; Link to comment https://forums.phpfreaks.com/topic/171967-solved-sprintf-variable-padding/#findComment-906747 Share on other sites More sharing options...
xiaix Posted August 26, 2009 Author Share Posted August 26, 2009 Ah, gotcha. I was scratching my head for hours as to why it wouldn't work. Didn't know that HTML wouldn't display padding like that. I'll use your advise with the <pre / > tags. Thanks for the quick response. Link to comment https://forums.phpfreaks.com/topic/171967-solved-sprintf-variable-padding/#findComment-906752 Share on other sites More sharing options...
xiaix Posted August 26, 2009 Author Share Posted August 26, 2009 *update* <pre> tags got messy, and after much trying to get things to pad correctly, I gave up and opted for table/row/columns to handle my text padding/justification issues. Everything works great now. Example: // Let's list armor defenses if ($howManyArmorDef>0) { $part .= sprintf("<BR /><strong>Defenses</strong><BR />"); $part .= sprintf("<table>"); if ($data1["e"] > 0) { $part .= sprintf("<tr><td>%+d</td><td>[%s]</td></tr>", $data1["e"], $defType["e"]); } if ($data1["f"] > 0) { $part .= sprintf("<tr><td>%+d</td><td>[%s]</td></tr>", $data1["f"], $defType["f"]); } if ($data1["g"] > 0) { $part .= sprintf("<tr><td>%+d</td><td>[%s]</td></tr>", $data1["g"], $defType["g"]); } if ($data1["h"] > 0) { $part .= sprintf("<tr><td>%+d</td><td>[%s]</td></tr>", $data1["h"], $defType["h"]); } if ($data1["i"] > 0) { $part .= sprintf("<tr><td>%+d</td><td>[%s]</td></tr>", $data1["i"], $defType["i"]); } if ($data1["j"] > 0) { $part .= sprintf("<tr><td>%+d</td><td>[%s]</td></tr>", $data1["j"], $defType["j"]); } $part .= sprintf("</table>"); } Link to comment https://forums.phpfreaks.com/topic/171967-solved-sprintf-variable-padding/#findComment-906843 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.