Jump to content


Help with preg_replace expression - newbie

  • Please log in to reply
1 reply to this topic

#1 spamalam

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 23 July 2006 - 11:28 AM

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

#2 ToonMariner

  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 28 July 2006 - 01:01 AM

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.
follow me on twitter @PHPsycho

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users