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