2

There is a string , say $x = "Poste : "; How to get $x's pixel length ? That is how many pixels does $x occupy ?

pheromix
  • 16,775
  • 24
  • 79
  • 150
  • Depends on font, bold, italic, etc – Mark Baker Jul 17 '12 at 08:53
  • 1
    There's not enough info. How is it printed? In what font: type face, size, weight, decoration, character spacing, etc. – Aleks G Jul 17 '12 at 08:53
  • 1
    Also, if I am using a 200% zoom, then? – hjpotter92 Jul 17 '12 at 08:54
  • 1
    As long as you output this string to a browser, only the browser knows how the text gets displayed. PHP knows nothing about it unless you produce some graphics via PHP. – mdo Jul 17 '12 at 08:54
  • makes little sense, may as well ask how much it will weight –  Jul 17 '12 at 08:55
  • 1
    Once you know all the font details, you can then use [this approach](http://stackoverflow.com/questions/1641756/how-to-determine-the-length-in-pixels-of-a-string-being-rendered-on-a-web-page) – Aleks G Jul 17 '12 at 08:55

1 Answers1

1

It does not exist. Indeed, each character in its own width depending on the font, the font size, style (bold, italic, normal, etc..).

A parade is to use a fixed-width font like Courier New style such as each character to the same width ;)

Clément Andraud
  • 8,707
  • 23
  • 75
  • 149