从php中获取字符串颜色的一些方法?

Ali*_*man 3 php

我有这样的字符串

$color="rgb(255, 255, 0)";
Run Code Online (Sandbox Code Playgroud)

我想在数组或三个不同的变量中获得值255,255,0.例如

$arr[0]=255;
$arr[1]=255;
$arr[2]=0;
Run Code Online (Sandbox Code Playgroud)

我认为可以在正则表达式中完成.但我很难受.谢谢

Tre*_*non 6

如果它始终采用该格式,那么这应该不使用正则表达式:

$color = str_replace(array('rgb(', ')', ' '), '', $color);
$arr = explode(',', $color);
Run Code Online (Sandbox Code Playgroud)

我们str_replace()用来删除不感兴趣的数据和空格,然后explode()用逗号表示字符串,以给出你想要的输出数组格式$arr.

我还将此解决方案添加到键盘中,以便您可以看到运行它时会发生什么.