2024-04-17 10:41:00
css文件(style.css)
.div1 {
width: 800px;
height: 322px;
}
.div2 {
width: 30px;
height: 14px;
}
php文件:
$css_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'style.css';
if (file_exists($css_file)){
$css_content = file_get_contents($css_file);
$css_content = preg_replace_callback('/width:\s*(\d+)px/im', 'callback_replace_width', $css_content);
file_put_contents($css_file, $css_content);
}
function callback_replace_width( $matches ){
if($matches[1]<600){
$matches[0] = 'width: ' . ($matches[1] * 1.5) . 'px';
};
return $matches[0];
}
输出结果:
.div1 {
width:800px;
height: 322px;
}
.div2 {
width: 45px;
height: 14px;
}
2024-04-17 00:10:26
2024-04-17 02:42:16
2024-04-17 03:00:17