TheFilmGod Posted October 5, 2007 Share Posted October 5, 2007 I want to take a string, and instead of php to count the # of characters in the string I want to know the lenght of the string in pixels in 12 font size verdana (not bolded). Because 10 characters can equal: MMMMMMMMMM or iiiiiiiiii So pretty much I have a text section in a webpage but the size of the text matters. If it has spaces, it may be shifted to the next line, and if it doesn't, it might not. And I don't want it fill up the page too much or shifting to more than 3 lines. How can I do this in php, or how I can create the text in css/html so that after x amout of pixels everything is taken out and replaced with "..." Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/71893-php-or-html-or-impossible/ Share on other sites More sharing options...
cooldude832 Posted October 5, 2007 Share Posted October 5, 2007 find the length in pixels of each character, store it as an array, then explode it apart at each charcter and say <?php $pixel_length["a"] = .05; $pixel_length["b"] = .75; $total = 0; foreach($exploded_string as $value){ $total += $pixel_length[$value]; } ?> get it? Quote Link to comment https://forums.phpfreaks.com/topic/71893-php-or-html-or-impossible/#findComment-362152 Share on other sites More sharing options...
trq Posted October 5, 2007 Share Posted October 5, 2007 In all honesty, this isn't going to happen. What happens when someone hits ctrl+ ? Also, different resolutions meen different sizes. Theres just too many variants. Quote Link to comment https://forums.phpfreaks.com/topic/71893-php-or-html-or-impossible/#findComment-362155 Share on other sites More sharing options...
cooldude832 Posted October 5, 2007 Share Posted October 5, 2007 true but that is just a scalar variation. So you can account for it, but as he said in all honesty its a no. If you trying to create a consistent design via CSS look into the em unit. It is by designed to create a uniform statement cross browsers/resolutions. Quote Link to comment https://forums.phpfreaks.com/topic/71893-php-or-html-or-impossible/#findComment-362162 Share on other sites More sharing options...
TheFilmGod Posted October 5, 2007 Author Share Posted October 5, 2007 true but that is just a scalar variation. So you can account for it, but as he said in all honesty its a no. If you trying to create a consistent design via CSS look into the em unit. It is by designed to create a uniform statement cross browsers/resolutions. Sure I'll look into the em unit, but HOW would I go around that. I appreciate all the help, its just there has to be a way. Quote Link to comment https://forums.phpfreaks.com/topic/71893-php-or-html-or-impossible/#findComment-362179 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.