これを試して:
$str1 = '<span style="font-family: arial;">Arial</span>';
$str2 = '<span style="font-size: 7px;">small text</span>';
$str3 = '<span style="color: skyblue;">Blue Text</span>';
$reg_exp= '/<span\s*style=\"\s*(.*?):\s*(.*?)\s*;\s*\">\s*(.*?)\s*<\/span>/';
$reg_exp_rep = '[$1=$2]$3[/$1]';
$text=preg_replace($reg_exp,$reg_exp_rep, $str1);
echo htmlspecialchars($str1).' <=> '.$text.'<br />';
$text=preg_replace($reg_exp,$reg_exp_rep, $str2);
echo htmlspecialchars($str2).' <=> '.$text.'<br />';
$text=preg_replace($reg_exp,$reg_exp_rep, $str3);
echo htmlspecialchars($str3).' <=> '.$text.'<br />';
結果:
<span style="font-family: arial;">Arial</span> <=> [font-family=arial]Arial[/font-family]
<span style="font-size: 7px;">small text</span> <=> [font-size=7px]small text[/font-size]
<span style="color: skyblue;">Blue Text</span> <=> [color=skyblue]Blue Text[/color]
これは、一般的な span タグ用です。より異なるタグ認識またはより具体的なものが必要な場合は、それを定義する必要があります。
--
編集:より具体的な、あなたが求めたもの。
unset($str1,$str2,$str3,$str4,$str5,$str6,$str7,$reg_exp);
$str1 = '
<span style="font-family: arial;">Arial</span>
<span style="font-size: 7px;">small text</span>
<span style="color: skyblue;">Blue Text</span>
<div align="center">centered text</div>';
$reg_exp[0] = '/<span\s*style=\"\s*(.*?):\s*(.*?)\s*;\s*\">\s*(.*?)\s*<\/span>/';
$reg_exp_rep[0] = '[$1=$2]$3[/$1]';
$reg_exp[1] = '/\[font-family(.*?)\/font-family\]/';
$reg_exp_rep[1] = '[FONT$1/FONT]';
$reg_exp[2]= '/\[font-size(.*?)\/font-size\]/';
$reg_exp_rep[2] = '[SIZE$1/SIZE]';
$reg_exp[3] = '/\[color(.*?)\/color\]/';
$reg_exp_rep[3] = '[COLOR$1/COLOR]';
$reg_exp[4] = '/<div\s*align=\"\s*center\s*"\s*\>\s*(.*?)\s*<\/div>/';
$reg_exp_rep[4]= '[CENTER]$1[/CENTER]';
$text=$str1;
foreach ($reg_exp as $ii => $exp) {
$text=preg_replace($exp,$reg_exp_rep[$ii], $text);
}
echo htmlspecialchars($str1).' <=> '.$text.'<br />';
結果:
<span style="font-family: arial;">Arial</span> <span style="font-size: 7px;">small text</span> <span style="color: skyblue;">Blue Text</span> <div align="center">centered text</div> <=>
[FONT=arial]Arial[/FONT] [SIZE=7px]small text[/SIZE] [COLOR=skyblue]Blue Text[/COLOR] [CENTER]centered text[/CENTER]