PHP中的strpos函数问题没有找到针

Jos*_*ton 4 php string

在php中我打开了一个.php文件,想要评估某些行.特别是当$ table_id和$ line变量赋值时.

在我的文本文件中:

...  
$table_id = 'crs_class';                      // table name
$screen   = 'crs_class.detail.screen.inc';    // file identifying screen structure
...
Run Code Online (Sandbox Code Playgroud)

等等.下面的if语句从不检测$table_idor的出现$screen(即使没有$ prepended).我无法理解为什么它不起作用,因为下面的strpos语句寻找'require'工作正常.

那么,为什么这个if语句不会受到影响呢?

while ($line=fgets($fh)) {
    //echo "Evaluating... $line <br>";
    **if ((($pos = stripos($line, '$table_id')) === true) || (($pos = stripos($line, '$screen'))===true))**
    {
        // TODO: Not evaluating tableid and screen lines correctly fix.
        // Set $table_id and $screen variables from task scripts
        eval($line);
    }

    if (($pos=stripos($line, 'require')) === true) { 
        $controller = $line;
    }
}
Run Code Online (Sandbox Code Playgroud)

Vol*_*erK 7

use!== false而不是=== true
stripos如果找到了针,则返回整数位置.这绝不是===布尔.
您可能也对PHP的tokenizer模块或pear存储库中的lexer包感兴趣.