tmyonline Posted February 16, 2008 Share Posted February 16, 2008 Dear all, Suppose I have a string "xyz". This string has length strlen("xyz") = 3. Is there a way to determine the length of this string in pixel instead ? In other words, how do I convert the value of 3 into pixel ? Thanks. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 16, 2008 Share Posted February 16, 2008 if it's a GD font use $textwidth = 3 * imagefontwidth('x'); If it's a truetype font, get the coords of it's bounding-box with imagettfbbox() Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 16, 2008 Share Posted February 16, 2008 can I ask what your intentions are for this? if you are looking for dynamic css look at the EM unit for font sizes its very nice Quote Link to comment Share on other sites More sharing options...
tmyonline Posted February 16, 2008 Author Share Posted February 16, 2008 Guys, what I want to do is this. I'm designing a menu as shown below: Chicken wings (3 pieces) ..............................................$4 Chicken wing, thigh, and breast .....................................$5.95 Chicken combo ...........................................................$12.75 I need to fill in the dots [.....................] between the menu item and the price in such a way that the prices align to the left. Because the menu items are of different lengths, I have to calculate their lengths, convert them into pixels, and subtract them from a fixed number to determine the lengths for the dots. I tried Barand's suggestion but it didn't work. But, thanks Barand, I appreciate your help. Hope to hear from others on this. Thanks. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 16, 2008 Share Posted February 16, 2008 Look into sprintf(). You can force a string to a certain length and choose the padding string (such as a dot in your case). The solution won't be immediately apparent but you should be able to get it with some tinkering. Quote Link to comment 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.