我真的需要一些帮助......我只是无法让它工作。
现在我有这段代码,它工作正常。它的作用是...根据名称中的日期重新调整目录中的所有文件。
<?php
header('Access-Control-Allow-Origin: *');
$imagesDir = '';
$images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
$filteredImages = [];
foreach($images as $image) {
$current_date = date("Ymd");
$file_date = substr($image, 0, 8);
if (strcmp($current_date, $file_date)>=0)
$filteredImages[] = $image;
}
echo json_encode($filteredImages, JSON_UNESCAPED_UNICODE);
?>
但现在我需要过滤这些文件(甚至可能在执行此代码之前)。根据他们名字中的字符串。
文件以下列方式命名:
yyyymmdd_xxxxxxx-xxxxxx~yyyymmdd.123456789.jpg
yyyymmdd_xxxxxxx-xxxxxx~yyyymmdd.9.jpg
yyyymmdd_xxxxxxx-xxxxxx~yyyymmdd.458.jpg
我只需要过滤掉最后(在"."
和之间".jpg"
)该数字串中具有特定数字的数字。数字9
$number = 9
我正在尝试使用这段代码来仅分隔名称的最后一部分:
<?php
function getBetween($jpgname,$start,$end){
$r = explode($start, $jpgname);
if (isset($r[1])){
$r = explode($end, $r[1]);
return $r[0];
}
return '';
}
$jpgname = "yyyymmdd_xxxxxxx-xxxxxx~yyyymmdd.12789.jpg";
$start = ".";
$end = ".jpg";
$output = getBetween($jpgname,$start,$end);
echo $output;
?>
我想我在所有这些中都需要 STRIPOS……但我现在迷路了……:(