Unexpected behavior from str_replace()

前端 未结 2 1502
清歌不尽
清歌不尽 2021-01-15 01:28

I have two arrays. One with color names and the other with the RGB values.

I am converting a color name to it\'s RGB value using str_replace() (then doi

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-15 01:44

    That's because str_replace() finds yellow first (Because it's before Pale Yellow in the array) and after this it can't find Pale anymore. So use strtr() instead, like this:

    $RGBvalue = strtr($colour, array_combine($RGBint, $ColourName));
    

提交回复
热议问题