Jump to content


This topic is now archived and is closed to further replies.


Help with preg_replace expression - newbie

Recommended Posts

I always seem to have trouble making regular expression strings.  Basically amazon have changed their site design and now there affiliates pictures have this white matting.  The thing is, amazon have the original images you just need to change the url a tiny bit

Essentially to remove the matting from:

you just have to change the url to


Now i'm having difficulty doing a regex that works, I figure something like this would do it:
$ret = preg_replace("[/]images[/]P[/](.*)(\.01\._SS500_SC)(LZZZZZZZ)(_V[0-9]*_)(\.jpg)","[/]images[/]P[/]\\1\.02\.\\3\\5", $ret);

But it complains.  Can't seem to wrap my head round the regex.

Thanks for the no doubt simple correction

ps. hope i posted in the right place

Share this post

Link to post
Share on other sites
Now not wanting to disappoint BUT is the only difference that '01' changes to '02' and
'_SS500_SC' and '_V1124758743_'?

basically you need to match patterns.

If the above were true then something like....

$lookfor = array('/\.01\._SS500_SC/' ,  '/_V(.)*_/');
$replace = array('.02.' ,  '');

$new = preg_replace( $lookfor, $replace ,$old);

see if that fits the bill.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.