Jump to content

[SOLVED] sprintf variable padding


xiaix

Recommended Posts

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
Share on other sites

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
Share on other sites

*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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.