【发布时间】:2011-03-24 20:03:26
【问题描述】:
我想扫描一个包含图像文件的目录并用它们填充我的数据库。图像具有常规且受控的名称,例如 top_1、top_200、bottom_3。我需要与“_”之前的单词匹配的正则表达式的帮助,因为它们中的每一个在数据库中都有不同的关系。
我现在可以扫描目录:
function scan_img_dir()
{
$dir = '/images/';
$scan = scandir($dir);
for ($i=0; $i<count($scan); $i++)
{
//Being Pseudocode
$stringBeforeUnderscore = Some_String_Manipulation($scan[$i]);
switch($stringBeforeUnderscore)
{
case 'top':
insert into db with the top relationship
break;
case 'bottom':
insert into db with the bottom relationship
break;
}
}
}
在“_”之前提取字符串的代码的任何帮助都会很棒。任何改进逻辑或代码的帮助都将是锦上添花!提前致谢。
【问题讨论】:
-
这非常有效。谢谢你。我最终选择了接受的答案,因为它更简单并且不会爆炸成数组。
标签: php codeigniter