Here's my problem. I want to get
2017
$str = explode("\","File=D:\Shared\print\2017\september\26\printing\baryun - cetak transferpaper.tif");
echo $str[count($str)-5];
File=D:\Shared\print\2017\september\26\printing\baryun - cetak transferpaper.tif
You can match it using ^File=D:\\[a-zA-Z]+\\[a-z]+\\([0-9]{4})
That is:
<?php
$line = 'File=D:\Shared\print\2017\september\26\printing\baryun - cetak transferpaper.tif';
$r = "/^File=D:\\\\[a-zA-Z]+\\\\[a-z]+\\\\([0-9]{4})\\\\([a-z]+)\\\\([0-9]{1,2})/";
if (preg_match($r, $line, $match)) {
print $match[1];
}
?>
To match the year, month and day, use ^File=D:\\\\[a-zA-Z]+\\\\[a-z]+\\\\([0-9]{4})\\\\([a-z]+)\\\\([0-9]{1,2})