foreach($files as $file) {
$xname = basename($file['name'],'.jpg');
$tmp = preg_split("/[\s,-]+/",$xname,-1, PREG_SPLIT_NO_EMPTY);
echo "<pre>";
print_r($tmp);
echo "</pre>";
这是示例字符串“LR-147-TKW FLOWER RECT MIRROR FRAME”
我有这行代码将我的字符串拆分为数组。我想要它做的是获取前 3 个单词,即“LR-147-TKW”并将其存储到一个变量中。我怎样才能做到这一点?我的数组输出是这个0] => BR
[1] => 139
[2] => TKW
[3] => DRESSER
[4] => BUFFET
[5] => MIRROR