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
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.