On Mon, 29 Apr 2002, District Webmaster wrote:
> In html/css you can set a font size in pixels -- in my experience this
> means a letter takes the same number of pixels, regardless of
> resolution. With php, can I use string length and font pixel size to
> determine the length of a given string on a screen? Does anyone know an
> algorithm for this that works for any/every font?

PHP is used to generate HTML. So anything you can type into your HTML 
file, PHP can output instead.

However, your base assumption, that it's possible to guess reliably how
many pixels wide a text string will be, is incorrect. Different people use
different browsers and have different fonts installed, and get different 
results. The best you can do is test in multiple environments and average 
the results - or use GD to create GIFs containing the text, in which case 
you can control the size precisely because it's using the fonts on your 
server instead of on someone else's client.


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to