【发布时间】:2019-08-11 19:15:45
【问题描述】:
我正在用 PHP 编写自己的计算器。
我的代码有问题,因为我不知道要在字符串中读取的位置太远。所以如果有人能启发我..
我得到的确切错误是:
PHP 注意:未初始化的字符串偏移量:/home/salim/Bureau/web/piscine_php/d01/ex11/do_op_2.php 第 76 行中的 4
下面是代码:
function decoupe ($argv)
{
global $nbr1;
global $nbr2;
global $sign;
$string = NULL;
$string = trim($argv[1], " \t");
echo $string;
echo "\n";
$x = 0;
while($string[$x])
{
if (is_numeric($string[0]) == false)
error_msg();
if (is_numeric($string[$x]) && $string[$x + 1])
{
while (is_numeric($string[$x]))
{
$nbr1 .= $string[$x];
$x++;
}
}
if (is_thisoperator(substr($string, $x)))
{
$sign .= $string[$x];
$x++;
}
else
{
error_msg();
}
if ($string[$x + 1] && is_numeric($string[$x]))
{
while (is_numeric($string[$x]))
{
$nbr2 .= $string[$x];
$x++;
}
}
else
{
error_msg();
}
}
【问题讨论】:
-
哪一行出现错误?
-
出现这个:if ($string[$x + 1] && is_numeric($string[$x]))
-
如果您想制作一个可用的算术评估器,同时只拔出最少的头发,您将希望与Shunting-Yard algorithm 友好相处。
标签: php string initialization offset notice