Reply to Re: [PHP] Seemingly weird regex problem

Your name:

Reply:


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

On Thu, 2005-01-20 at 14:06, Bret Hughes wrote:

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


Well it sure is easier to debug when you are looking at the right
frigging function. I think the logic error is still similar you are
comparing two values that are not meant to be compared.

Since if an integer is involved in a comparison, and it is here since
preg_match returns an integer, the string will be converted to an
integer. IIRC string to integer conversion results in 0 if the string
does not look like number.

Since the match is not found, preg_match returns 0 compared to the
string contained in $line will be converted to 0 ( if it begins with a
letter its integer represetation is 0) the case mathes and the block
executes.

That and the first case is totally misued. you are trying to use the
switch as a series of ifs and the analogy only holds true if the
comparison is the same.

I would not hesitate to rewrite this and encourage you to do so because
even if you get it to work as intended it is not clear what you are
trying to do.

Bret

[Back to original 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

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