Re: strpos question
- From: Erwin Moller <since_humans_read_this_I_am_spammed_too_much@xxxxxxxxxxxxxxxx>
- Date: Thu, 29 Jun 2006 17:16:43 +0200
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
.
- References:
- strpos question
- From: drec
- strpos question
- Prev by Date: Re: Convert text
- Next by Date: Re: strpos question
- Previous by thread: strpos question
- Next by thread: Re: strpos question
- Index(es):
Relevant Pages
|