Re: Pixel Length of text message
| From: | Miguel Cruz | Date: | Mon, 29 Apr 2002 16:49:29 +0000 |
| Subject: | Re: Pixel Length of text message | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-95197@lists.php.net to get a copy of this message | ||
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.
miguel