簡體   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