|
Posted by gosha bine on 08/24/07 15:23
On 24.08.2007 01:16 windandwaves wrote:
> Hi Folk
>
> I was wondering if I could do the following:
>
> write a php function that changes a stylesheet from 1024x768 to one
> for 800x600 by literally changing all the widths, heights, font-sizes,
> etc... by the ratio between 800/1024 (i.e. multiplying all values to
> do with height or length with 0.78125)
>
> My question is how I would write a regular expression that replaces as
> follows:
>
> YYYpx to ZZZpx
> YYYem to ZZZem
> YYYpt to ZZZpt
> YYY% to ZZZ%
>
> where YYY is the original numerical value and ZZZ = YYY * 0.78125.
>
> Could you please help me to write this regular expression to test this
> theory?
>
assuming your stylesheet is in the variable $css,
$css = preg_replace_callback('/\d+(?=\s*(px|em|pt|%))/', 'convert', $css);
function convert($m) {
return round($m[0] * 800 / 1024);
}
hope this helps
--
gosha bine
makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
[Back to original message]
|