私は文字列を持っています
$style = "font-color:#000;font-weight:bold;background-color:#fff";
私だけが必要です
font-color
font-weight
background-color
私が試してみました
preg_match_all('/(?<names>[a-z\-]+:)/', $style, $matches);
var_dump($matches);
次の出力が得られます
array
0 =>
array
0 => string 'font-color:' (length=11)
1 => string 'font-weight:' (length=12)
2 => string 'background-color:' (length=17)
'names' =>
array
0 => string 'font-color:' (length=11)
1 => string 'font-weight:' (length=12)
2 => string 'background-color:' (length=17)
1 =>
array
0 => string 'font-color:' (length=11)
1 => string 'font-weight:' (length=12)
2 => string 'background-color:' (length=17)
この出力 1 には 3 つの問題があります。これは 2 次元または 3 次元の配列です。1 次元の配列が必要です。2. 情報を繰り返しています。 3. 各要素の末尾に「:」を追加しています。
このような単一の配列が必要です
array
0 => 'font-color'
1 => 'font-weight'
2 => 'background-color'