|  | Posted by Peter on 09/05/07 21:30 
Thank you Ian,
 > 1) The width and height (and border) all have digits between the quotes,
 > yet your pattern has dots. Dot matches any character except newline, which
 > is why your expression matched too much.
 
 I see !  Indeed, your suggestion "(\d*) should fix that rather nicely !
 
 Out of curiosity ... what if there could be anything (except newline)
 between the quotes ?
 I mean, can preg_replace() be told to stop on the first occurance rather
 than last occurance, e.g. when it finds the first matching BORDER=\"0\"
 instead of the last one before newline ?
 
 > 2) You state you want to change <IMG tags, but your code changes anything
 > with WIDTH and HEIGHT and BORDER. Only you can confirm these are the same.
 
 I know but I happen to know that this works for these generated files so I
 didn't bother with more security checks.
 
 > 3) You match more than required, and then put it back again...
 
 I know but now thinking about it, I think I did this for a similar reason.
 Before I put 'BORDER' in the pattern the replace() replaced too much, it
 replaced everything till the last qoute on the line, instead of the first
 one after/inside (.*)
 
 > I note that you mention alterations in the plural. Both $pattern and
 > $replace can be arrays, and preg_replace will perform all changes at once
 > rather efficiently.
 
 Thanks for the tip !!
  Navigation: [Reply to this message] |