Jump to content

Help with preg_replace expression - newbie


spamalam

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:
http://images.amazon.com/images/P/B00005LQ0Z[b].01._SS500_SC[/b]LZZZZZZZ[b]_V1124758743_[/b].jpg

you just have to change the url to
http://images.amazon.com/images/P/B00005LQ0Z[b].02.[/b]LZZZZZZZ.jpg

eg:
http://images.amazon.com/images/P/B00005LQ0Z.01._SS500_SCLZZZZZZZ_V1124758743_.jpg
http://images.amazon.com/images/P/B00005LQ0Z.02.LZZZZZZZ.jpg

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
Link to comment
https://forums.phpfreaks.com/topic/15384-help-with-preg_replace-expression-newbie/
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.

Archived

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

×
×
  • Create New...

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.