Forum Moderators: coopster
- Numbers
- special characters (){}[]@$% etc
- patterns 1600x1200, 800x600, 1024 x 786, 1024 X 786
X can be capital or small i have written all the rules but problem with below code is its stripping X or x from the text.
$file = '3d MetarelicXx, - ([1600x1200]).JPG';
$ext = strrchr($file, '.');
$name = str_replace("3d","#d",$file);
$name = str_replace("3D","#d",$name);
$name = preg_replace('/([0-9 x 0-9])/', ' ', $name);
$name = preg_replace('/([0-9x0-9])/', ' ', $name);
$name = preg_replace('/([0-9X0-9])/', ' ', $name);
$name = preg_replace('/([0-9])/','',$name);
$name = preg_replace('/([-_%])/', ' ', $name);
$name = preg_replace('/([+(),\[\]])/', ' ', $name);
$name = trim(str_replace($ext,'',$name));
$name = str_replace('#d','3D',$name);
$name = ucwords($name);
any suggestion?
It's because you're using character classes and the x qualifies.
Try this one line instead of those three:
$name=preg_replace('/(\d+ {0,1}x {0,1}\d+)/i','',$name);
This pattern is satisfied by 1 or more digits followed by an optional space followed by an x followed by an optional space followed by 1 or more digits. The i at the end causes it to be case insensitive.
$name=preg_replace('/(\d+ {0,1}x {0,1}\d+)/i','',$name);
$name=preg_replace('/(\d+?x?\d+)/i','',$name); // where have all the spaces gone?
Although after having previewed this with the? the space disappears :( so I guess that is why the original {} is in there.
So to keep the forum happy
$name=preg_replace('/(\d+[ ]?x[ ]?\d+)/i','',$name);