简体   繁体   中英

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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