简体   繁体   English

使用HTML / CSS内容将字符串中的字体大小加倍

[英]Double the font-size in string with HTML/CSS content

I've got a string like this: 我有一个像这样的字符串:

$foo = 'height:200px;color:#CCC;font-size:12px';

Can I somehow double the font-size amount in the string? 我能以某种方式将字符串中的字体大小加倍吗?

Try with: 试试:

$foo  = 'height:200px;color:#CCC;font-size:12px';
$key  = 'font-size:';
preg_match('/' . $key . '(\d+)/', $foo, $matches);
$size = (int) $matches[1];
$foo  = str_replace($key . $size, $key . ($size * 2), $foo);

can you please used this code : 你可以请用这个代码:

<?php

$foo = 'height:200px;color:#CCC;font-size:12px';
$styleArr   = explode(";",$foo);
$newStyleArr    = array();
foreach ($styleArr as $style) {
    $explode_str    = explode(":",$style);
    if($explode_str[0]=="font-size" && count($explode_str)>0) {
        $explode_str[1] = str_replace("px","",$explode_str[1]);
        $explode_str[1]     = ($explode_str[1]*2)."px;";
    }

    $newStyleArr[]  = implode(":",$explode_str);
}

echo implode(";",$newStyleArr);
?>

OUTPUT : 输出:

height:200px;color:#CCC;font-size:24px;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM