繁体   English   中英

如何在我的文本中间获取某个字符串

[英]How to get a certain string in the middle of a my text

所以我在数据库中存储了RGB颜色代码,我想要的是检索整个rgb代码,例如(rgb(0,255,128)我只想检索0、255和128,我尝试使用trim,但是没有好。

$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'];

检索数据时,我不知道下一步该怎么做。 请帮我

在这里使用正则表达式是一个好主意

preg_match("/rgb\((\d+), (\d+), (\d+)\)/", "rgb(0, 255, 128)", $rgb);

之后, $rgb将包含您的颜色值

$rgb[1] == 0;
$rgb[2] == 255;
$rgb[3] == 128;
$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);

输出量

Array
(
    [0] => 122
    [1] => 132
    [2] => 244
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM