|
Posted by Aaron Saray on 09/06/07 23:28
On Sep 5, 4:30 pm, "Peter" <Will_Bounce_So_Use_My_First_N...@Smart-
Projects.net> wrote:
> 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 !!
You may want to use (.*?) I think... this will make it not greedy -
and will only continue to match up to the next time your next part of
your statement is hit.
[Back to original message]
|