Are the ranges constantly defined? Or are they variable? I.e. will the first set of numbers always be between 01 and 15, or can it go form 01 to 99 and the second sent the same?
I guess the easiest thing to do would be to remove the url in the string, and drop the ".jpg" portion. Then, the length of the string your left with has to be 2, or 4. So you split it by 2 and you've got your numbers 😉
$baseURL = 'http://www.mysite.com/images/img';
$ext = '.jpg';
$images = array(
'http://www.mysite.com/images/img0120.jpg',
'http://www.mysite.com/images/img0221.jpg',
'http://www.mysite.com/images/img0322.jpg',
'http://www.mysite.com/images/img0423.jpg',
'http://www.mysite.com/images/img0524.jpg',
);
foreach($images as $img)
{
$img = str_replace($baseURL, '', $img);
$img = str_replace($ext, '', $img);
if(phpversion() > 5)
{
$elmts[] = str_split($img, 2);
}
else
{
$tmp = chunk_split($img, 2, ':');
$tmp = substr($tmp, 0, -1); // Get rid of errneous :
$elmts[] = explode(':', $tmp);
}
}
print_r($elmts);
// Or to do the reverse, from array to urls:
foreach($elmts as $elm)
{
echo $baseURL.implode('', $elm).$ext.'<br />';
}
Hope that helps.