Reputation: 4632
So I have RGB color codes stored in my database, what I want is instead retrieving a whole rgb code e.g (rgb(0, 255, 128) I only want to retrieve the 0, 255 and 128, I tried using trim, but no good.
$sql32="select * from tooth";
$q32=mysql_query($sql32) or die(mysql_error());
$row32=mysql_num_rows($q32);
$r32=mysql_fetch_assoc($q32);
$rgbcol=$r32['t_color'];
I don't know what to do next when I retrieved the data. please help me
Upvotes: 0
Views: 40
Reputation: 32392
$r32['t_color'] = "rgb(122,132,244)";
//remove everything except numbers and comma
$rgbcol = preg_replace("/[^0-9,]/", "", $r32['t_color']);
$rgbcol = explode(',',$rgbcol);
print_r($rgbcol);
Output
Array
(
[0] => 122
[1] => 132
[2] => 244
)
Upvotes: 2
Reputation: 225
Using regular expressions here would be a good idea
preg_match("/rgb\((\d+), (\d+), (\d+)\)/", "rgb(0, 255, 128)", $rgb);
after this, $rgb
will contain your color values
$rgb[1] == 0;
$rgb[2] == 255;
$rgb[3] == 128;
Upvotes: 5