homer.favenir Posted November 26, 2008 Share Posted November 26, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/134338-solved-string-align-to-right-regex/ Share on other sites More sharing options...
gaza165 Posted November 26, 2008 Share Posted November 26, 2008 <?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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/134338-solved-string-align-to-right-regex/#findComment-699403 Share on other sites More sharing options...
homer.favenir Posted November 26, 2008 Author Share Posted November 26, 2008 by the way my output is text file. i want my output in text file to align in right. is there any function or other way to do it? thanks Quote Link to comment https://forums.phpfreaks.com/topic/134338-solved-string-align-to-right-regex/#findComment-699412 Share on other sites More sharing options...
gaza165 Posted November 26, 2008 Share Posted November 26, 2008 Im not 100% sure but i think you can do something like.... <?php fwrite ($ratetable, "html {text-align: right; }"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/134338-solved-string-align-to-right-regex/#findComment-699414 Share on other sites More sharing options...
homer.favenir Posted November 26, 2008 Author Share Posted November 26, 2008 where is the $ratestr? Quote Link to comment https://forums.phpfreaks.com/topic/134338-solved-string-align-to-right-regex/#findComment-699415 Share on other sites More sharing options...
gaza165 Posted November 26, 2008 Share Posted November 26, 2008 Just realised that would never work.... the code ive just submitted would just write into the text file with that html text.. let me look further into it... Quote Link to comment https://forums.phpfreaks.com/topic/134338-solved-string-align-to-right-regex/#findComment-699416 Share on other sites More sharing options...
sasa Posted November 26, 2008 Share Posted November 26, 2008 use str_pad function to change length of string before raplace it Quote Link to comment https://forums.phpfreaks.com/topic/134338-solved-string-align-to-right-regex/#findComment-699588 Share on other sites More sharing options...
homer.favenir Posted November 27, 2008 Author Share Posted November 27, 2008 thanks Quote Link to comment https://forums.phpfreaks.com/topic/134338-solved-string-align-to-right-regex/#findComment-699934 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.