PHP - Split string on specific characters

时间:2015-05-12 22:46:45

标签: php string split

I'm working on a project where I downloaded thousands laws from the governments website (legality all in order). I am trying to split the name of the files so I can sort them better in my website. The file is designed as such

e.Location.Y

I am running a foreach loop on the 48600003801.html function. I have around 20,000+ files as such. I want to do the following:

scandir()

How would I go about splitting such a string type up seeing that they are almost all different lengths?

2 个答案:

答案 0 :(得分:1)

try this:

blocks

答案 1 :(得分:0)

$array=[0 => '65437890657.html', 1 => '987121340098.html', 2 => '98073517639.html'];
$i=0; $s=substr; $arrey=[];
foreach($array as $file) {
    $file = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file);
    $arrey[$i]['chapter']=$s($file, 0, 3);
    $arrey[$i]['article']=$s($file, 3, 3);
    $arrey[$i]['section']=$s($file, 6, 4);
    $arrey[$i]['irrelevant']=$s($file, -1, 1);
    $i++;
}

print_r($arrey);