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
https://forums.phpfreaks.com/topic/134338-solved-string-align-to-right-regex/
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>";
?>

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.