Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.