- var_dump: documentation ( source)
- preg_split: documentation ( source)
<?php
$pattern = '/,\s?/';
$filenames = 'filename.png,filename.png,filename.png,filename.png,file name.png';
var_dump(preg_split($pattern, $filenames));
$filenames = 'filename.png, filename2.png, filename3.png, filename4.png, file name5.png';
var_dump(preg_split($pattern, $filenames));