如何匹配数组列表中的字符串,如果没有找到,那么找到与PHP匹配的最接近的字符串?

时间:2016-11-21 07:06:46

标签: php regex preg-replace preg-match-all

$pattern = "/#(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{3})\b/";
if(preg_match_all($pattern, $file, $matches, PREG_PATTERN_ORDER));
$data["colors"] = $matches[0];

所以基本上我需要做的是操纵一个SVG图像,这样我们就可以计算颜色的数量并使用php改变该图像的颜色。从上面的代码我可以找到正在使用的颜色,但问题是我必须匹配另一种颜色数组中的颜色,如果十六进制代码不匹配,那么我必须选择与该颜色最接近的匹配。我必须能够将该信息保存到SVG文件中。

这是我的Color Array:

$pantone = [
    [
        "Pantone" => "Yellow",
        "Hex" => "FEDD00",
        "R" => "254",
        "G" => "221",
        "B" => "0"
    ],
    [
        "Pantone" => "Yellow 012",
        "Hex" => "FFD700",
        "R" => "255",
        "G" => "215",
        "B" => "0"
    ],
    [
        "Pantone" => "Orange 021",
        "Hex" => "FE5000",
        "R" => "254",
        "G" => "80",
        "B" => "0"
    ],
    [
        "Pantone" => "Warm Red",
        "Hex" => "F9423A",
        "R" => "249",
        "G" => "66",
        "B" => "58"
    ],
    [
        "Pantone" => "Red 032",
        "Hex" => "EF3340",
        "R" => "239",
        "G" => "51",
        "B" => "64"
    ],
    [
        "Pantone" => "Rubine Red",
        "Hex" => "CE0058",
        "R" => "206",
        "G" => "0",
        "B" => "88"
    ],
    [
        "Pantone" => "Rhodamine Red",
        "Hex" => "E10098",
        "R" => "225",
        "G" => "0",
        "B" => "152"
    ],
];

这是我SVG with Regex

的链接

如果我的问题不完整,请通知我。

0 个答案:

没有答案