Jump to content

Php or Html or impossible?


TheFilmGod

Recommended Posts

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!  ;D:D

Link to comment
https://forums.phpfreaks.com/topic/71893-php-or-html-or-impossible/
Share on other sites

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?

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.

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.

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.