获取实际宽度而不是自动使用PHP

How can I determine the explicit width of a HTML element that has width auto using PHP?

JQuery has the ability to do this if width:auto; is used it can compute the actual width.

Get the current computed width for the first element in the set of matched elements.

JQuery probably does this with the help of the browser as it is client side.

How can I achieve this using PHP? I have the HTML as a string.

Update

All CSS is inline, if the width is auto, the only thing left to determine the width of the element is its immediate parent and/or its contents.

The only way this would be possible in PHP is if you have both the HTML and the complete CSS as strings AND the width of the element is defined in absolute pixels or the width of its container (or the parent's container, etc) is defined in absolute pixels. If all these conditions were true, it would still be extremely difficult to figure out. Basically you'd have to code a rendering engine in PHP.

If you were really lucky, the element you needed would have an inline style="width:px" and you could parse for that attribute.

This is possible in Javascript because the browser knows its own size. Under most circumstances, the HTML in a string doesn't have a size until rendered in a browser.

It is not possible. PHP does not know how the HTML/CSS will be rendered (if rendered at all).