从SQL列中抓取数据并将其拆分为填充函数

时间:2016-03-31 08:53:11

标签: php split setter

如果我从数据库中名为image_store的列中获取数据,例如:

/web/images/data/firstImage.png
/web/images/data/secondImage.png
/web/images/data/thirdImage.png

我想填充一个setImage函数,该函数将/data/之后的字符串设置为fileName,将/firstImage.png之前的字符串设置为目录,例如:

$this->setImage('firstImage.png', '/web/images/data/')

有没有办法可以从我从数据库中找回的字符串中获取所需的信息?

1 个答案:

答案 0 :(得分:1)

是的,只需使用 $timenow = time(); $start_time = strtotime('+15 minutes', $timenow); // round to next 15 minutes (15 * 60 seconds) $start_time = ceil($start_time / (5 * 60)) * (5 * 60); //set the start times $opentime = strtotime('10:00'); $closetime = strtotime('11:55'); // get a list of prebooked slots from database $time_slots = $this->countStartTimes(); $available_slots = array(); while($start_time <= $closetime && $start_time >= $opentime) { $key = date('H:i', $start_time); if(array_key_exists($key, $time_slots)) { if($time_slots[$key] == SLOTS) { $available_slots[] = 'FULL'; break; } } $available_slots[] = date('H:i', $start_time); $start_time = strtotime('+5 minutes', $start_time); } 个功能和explode/implode自行获取图片名称:

array_pop()

这适用于任何深度的url路径。