You are here: Re: [PHP] Seemingly weird regex problem « PHP « IT news, forums, messages
Re: [PHP] Seemingly weird regex problem

Posted by Bret Hughes on 01/20/05 22:06

On Thu, 2005-01-20 at 13:21, Tim Boring wrote:
> On Thu, 2005-01-20 at 13:41, Jason Wong wrote:
> > On Friday 21 January 2005 01:52, Tim Boring wrote:
> >
> > Well the biggest problem in your code right now is your incomprehensible (to
> > me anyway) use of the switch construct. For a start I've no idea why you're
> > using ...
> >
> > > switch ($line)
> >
> > ... when your tests do not involve $line
> >
> > > case ($total_counter <= 5):
>
> I see your point, but the other tests do involve $line. This one that
> you reference I'm using for a "special need"--basically so I leave in
> the initial column headings from the report, because they would match
> several of the tests that would discard those lines.
>
> >
> > I suspect what you want to be doing is something like this:
> >
> > switch (TRUE) {
> > case ANY_EXPRESSION_THAT_EVALUATES_TO_TRUE:
> > ...
> > }
>
> Thanks for the suggestion, but I'm not sure that does what I'm looking
> for. I really think the problem is with my regex, not necessarily with
> the way I've constructed my switch statement.
>
> I say this because I have since changed the first word in each line from
> something like "AKRN" to a numeric value, and everything works just as I
> would expect it to. So it seems as if the "^" might be negating the \W+
> part of the regex. Although that shouldn't be happening because "^"
> only acts as a negation when it's used inside brackets, at least
> according the documentation.
>
> Again, thanks for the suggestion!
>

I think I see a possible explanation for the behavior. preg_replace
does not return a true or false value it returns the string passed as
the subject with any matched replacements done. Hmm the manual says it
better:

If matches are found, the new subject will be returned, otherwise
subject will be returned unchanged.

What I think is happening is that the first match is not finding
anything to replace and returning $line unchanged. the comparison is
true since you are comparing to $line in the switch statement.

I will p[lay with it a bit since it pisses me off when I can't figure
out what is happening.

Bret

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация