This question already has an answer here:
这个问题在这里已有答案:
- PHP parse/syntax errors; and how to solve them? 16 answers
PHP解析/语法错误;以及如何解决它们? 16个答案
I have a string which will be added from the user
我有一个字符串,将从用户添加
I will separate the string into an array I'll separate each character alone
我将字符串分成一个数组,我将单独分隔每个字符
then I want to find a specific word which is
那么我想找一个特定的词
if(
this is my code but I got an error
这是我的代码,但我收到了一个错误
$StingFromTheUser = 'public class a
{
if(int i=0; i<10; i++)
{
//any thing
}
} '//end of the string
I separate it using this code which is correct
我使用这个正确的代码分开它
$arr = str_split($StringFromTheUser);
Now I want to find if the code has if statement or not so I'm going to search for the word
现在我想找到代码是否有if语句,所以我要搜索这个单词
if(
here is my code
这是我的代码
for($i=0; $i<count($arr)-2; $i++)
{
if(arr[$i]=='i' && arr[$i+1]=='f' && arr[$i+2]=='(')
{
echo $arr[$i].$arr[$i+1].$arr[$i+2];
}
}
but unfortunately I got this error
但不幸的是我收到了这个错误
Parse error: syntax error, unexpected '[' in /fileName.php on line 331
解析错误:语法错误,第331行的/fileName.php中的意外'['
2 个解决方案
#1
if($arr[$i]=='i' && $arr[$i+1]=='f' && $arr[$i+2]=='(')
Use $ infront of arr
使用$ infront of arr
#2
you forget $
in your arr
你忘了你的arr
it would be
这将是
if($arr[$i]=='i' && $arr[$i+1]=='f' && $arr[$i+2]=='(')
{
echo $arr[$i].$arr[$i+1].$arr[$i+2];
}
and you use if
in for
condition:-
并且你使用if in for condition: -
for(int i=0; i<10; i++)
{
//any thing
}
#1
if($arr[$i]=='i' && $arr[$i+1]=='f' && $arr[$i+2]=='(')
Use $ infront of arr
使用$ infront of arr
#2
you forget $
in your arr
你忘了你的arr
it would be
这将是
if($arr[$i]=='i' && $arr[$i+1]=='f' && $arr[$i+2]=='(')
{
echo $arr[$i].$arr[$i+1].$arr[$i+2];
}
and you use if
in for
condition:-
并且你使用if in for condition: -
for(int i=0; i<10; i++)
{
//any thing
}