Re: strpos question



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

.



Relevant Pages

  • NOCC Webmail <= 1.0 multiple vulnerabilities
    ... "NOCC is a webmail client written in PHP. ... remote code execution, there are two ways of execute arbitrary code on ... is defined in conf.php, by default no path is defined, but script suggests ... echo nl2br); ...
    (Bugtraq)
  • Re: [PHP] Help with an error...
    ... I am currently working on a php script that will be called by cron. ... echo 'This could not be display due to a system error. ...
    (php.general)
  • Re: [PHP] Help with an error...
    ... I am currently working on a php script that will be called by cron. ... echo 'This could not be display due to a system error. ...
    (php.general)
  • Re: [PHP] Help with an error...
    ... Also, if you want HTML tags in your PHP code, you need to end and start ... I am currently working on a php script that will be called by cron. ... echo 'This could not be display due to a system ...
    (php.general)
  • Re: php in database entry...
    ... in my main php file i retrieve the field and i echo it ... now i need in this field to have a php script to ...
    (comp.lang.php)