在 php 中,我打开了一个 .php 文件并想评估某些行。特别是当 $table_id 和 $line 变量被赋值时。
在我的文本文件中:
...
$table_id = 'crs_class'; // table name
$screen = 'crs_class.detail.screen.inc'; // file identifying screen structure
...
除其他外。下面的 if 语句永远不会检测到 $table_id
或 $screen
的出现(即使没有 $ 前缀)。我不明白为什么它不起作用,因为下面查找“require”的 strpos 语句工作正常。
那么,为什么这个 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;
}
}
最佳答案
使用 !==false 而不是 ===true
如果找到针,stripos 会以整数形式返回位置。那永远不会=== bool。
您可能还对 PHP 的 tokenizer module 感兴趣或 lexer package在 pear 存储库中。
关于php - PHP 中的 strpos 函数问题找不到针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/83397/