Jump to content

[SOLVED] string align to right (regex)


homer.favenir

Recommended Posts

hi,

how can i align my string to the right ?

this is my script

<?php
fwrite($ratetable, 'UDACRate'."\r\n");
while($row = mysql_fetch_array($rate))
	{
		echo "<tr>";
		echo "<td>" . $row['Udac Code'] . "</td>";
		echo "<td>" . $row['Occurances'] . "</td>";
		echo "<td>" . $row['Udac Rate'] . "</td>";
		echo "</tr>";
		$ratestr = substr_replace($ratestr1, $row['Udac Code'], 0, 10);
		$ratestr = substr_replace($ratestr, $row['Occurances'], 11, 10);
		$ratestr = substr_replace($ratestr, $row['Udac Rate'].".00", 20, 10);
		$ratestr = str_replace("|"," ", $ratestr);
		fwrite($ratetable, $ratestr."\r\n");
	}
	echo "</table>";
?>

 

this is the output

UDACRate
2HS        413      924.00                           
3HS        145      1224.00                           
3HS1       29       1596.00                           
3HSA       125      1225.00                            
3HSAC      9        1597.00                           
4HS        66       1536.00                          
4HS1       12       1992.00                           
4HSA       84       1537.00                           
4HSAC      11       1993.00                            
5HS        1        1836.00                         
5HS1       2        2388.00                          
5HSA       3        1837.00                          
5HSAC      2        2389.00                           
6HS        9        2148.00                         
6HS1       9        2796.00                          
6HSA       9        2149.00                          
6HSAC      7        2797.00                           
ABLN       3429     0.00                            
AL         116      120.00                          
BLN        418      240.00                           
CC         1        15300.00                        
CPN        237      601.00                           
CPNWP      5        600.00                           
CS         1        27960.00                        
CTM        2        1440.00                         
DHC        127      5664.00                           
DHC1       16       6228.00                           
DHCW       51       6804.00                           
DHCW1      18       7920.00                            
DHCW2      45       8521.00                            
DHCWP      155      8520.00                      

i want my output's last column (integer with decimal zeros) to be align to the right

 

can anyone PLEASE help....

 

thanks

 

 

Link to comment
Share on other sites

<?php
fwrite($ratetable, 'UDACRate'."\r\n");
   while($row = mysql_fetch_array($rate))
      {
         echo "<tr>";
         echo "<td>" . $row['Udac Code'] . "</td>";
         echo "<td>" . $row['Occurances'] . "</td>";
         echo "<td style='text-align:right;'>" . $row['Udac Rate'] . "</td>"; //Add come css...
         echo "</tr>";
         $ratestr = substr_replace($ratestr1, $row['Udac Code'], 0, 10);
         $ratestr = substr_replace($ratestr, $row['Occurances'], 11, 10);
         $ratestr = substr_replace($ratestr, $row['Udac Rate'].".00", 20, 10);
         $ratestr = str_replace("|"," ", $ratestr);
         fwrite($ratetable, $ratestr."\r\n");
      }
      echo "</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.