There is absolutely no way to know how wide the string will be in pixels, from the server side. You can take a guess, by rendering the string using the same font you specify in your CSS, however the end-user can override those settings in their browser, making your guess invalid. Or, the user might not have the font you do, and the browser substitutes one from a similar family, which has different widths for certain characters; The result again is going to be different from what you thought.
The only way to know, if it's even possible, would be to use JavaScript in the user's browser, basing the calculation on what the final rendered font is, as specified by any user-CSS, then return that to your server for further processing, however that really breaks down the idea of how the web and browsers work.