Parse inline CSS values with Regex?

前端 未结 4 1829
Happy的楠姐
Happy的楠姐 2021-01-19 03:57

I have such an inline CSS like this

color:#777;font-size:16px;font-weight:bold;left:214px;position:relative;top:70px

The CSS may

4条回答
  •  终归单人心
    2021-01-19 04:35

    Here's a quick-and-dirty script that does what you're asking:

     0) {
          $kv = explode(":", trim($attr));
          $parsed[trim($kv[0])] = trim($kv[1]);
       }
    }
    ?>
    

    And the output of print_r($parsed) is:

    Array
    (
       [color] => #777
       [font-size] => 16px
       [font-weight] => bold
       [left] => 214px
       [position] => relative
       [top] => 70px
    )
    

提交回复
热议问题