You are here: Re: strpos question « PHP Programming Language « IT news, forums, messages
Re: strpos question

Posted by Erwin Moller on 12/17/03 11:51

drec wrote:

> I am trying to right an if statment using strpos to determine if the
> string exists in the variable, however I seem to be getting the wrong
> effect. Here is my script.
>
> <?php
> $dn = "ABC-DEF";
>
> $pos = strpos( $dn, "ABC-DEF" );
> if ( $pos != FALSE )
> {
> echo 'variable contains value';
> }
> else
> {
> echo ' variable does not contain value' ;
> }
> ?>
>
> It keeps returning does not contain value. I am kinda new to strpos,
> any suggestions?

Yes, read the manual. :-)

It is such a common mistake php.net shouts a warning when describing the
function.

Read this:
http://nl2.php.net/manual/en/function.strpos.php

[quote]
Warning

This function may return Boolean FALSE, but may also return a non-Boolean
value which evaluates to FALSE, such as 0 or "". Please read the section on
Booleans for more information. Use the === operator for testing the return
value of this function.
[/quote]

I think yours is a typical 0 that evaluates to false.


Regards,
Erwin Moller

 

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

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