Jump to content

String length by pixels, NOT characters???


paco_santigo
 Share

Recommended Posts

Is there a function to count the length of a string as the pixel length, instead of the character count????Im asking because some characters "W" are wider than others "i".I'm currently using "Strlen", but it doesn't always work.I remember coming across something online awhile ago about em being used somehow to figure this out.... not sure exactly. but is there a way?

Link to comment
Share on other sites

If you're using a monospaced font then it's easy enough to calculate, all the letters are the same width. The only other way I can think of is using the GD image library, you can create a string in a certain font and it will tell you what the size of the bounding box is for the text.http://www.php.net/manual/en/function.imageftbbox.phphttp://www.php.net/manual/en/function.imagepsbbox.phphttp://www.php.net/manual/en/function.imagettfbbox.php

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...