在大型PHP文件中找到丢失的大括号?

时间:2021-10-06 22:44:29

I'm debugging a client's 3500-line PHP file. Including this file causes a PHP Parse error: syntax error, unexpected $end in ... error, so I'm assuming there's a missing brace somewhere. Is there a simple tool or method for missing brace discovery, either online or in the Komodo IDE I'm using?

我正在调试一个客户机的3500行PHP文件。包含此文件将导致PHP解析错误:语法错误,意外的$end in…错误,假设这里有一个缺失的括号。有没有一种简单的工具或方法可以在网上或在我正在使用的Komodo IDE中发现丢失支撑?

7 个解决方案

#1


2  

Use consistent and clean tabbing. I've found that makes it very hard to miss a closing brace.

使用一致和干净的表格。我发现,这让我们很难错过最后一击。

Other than that, you've kinda dug your own grave here. What are you coding that results in a 3500-line PHP file?

除此之外,你还在这里挖了自己的坟墓。您正在编写什么代码来生成一个3500行PHP文件?

EDIT: Try dumping your code into Notepad++. I'm fairly sure that will highlight the associated closing brace if you click on the opening one, but with larger files, I've gotten somewhat unreliable performance with this.

编辑:试着把你的代码放到记事本++中。我敢肯定,如果你点击打开的文件,它会突出显示相关的关闭括号,但是对于较大的文件,我已经获得了一些不可靠的性能。

#2


2  

another option (similar to notepad++) is to use Dreamweaver to find the associated closing tag.
See this link: How do I make Dreamweaver to show me closing tags?

另一个选项(类似于notepad++)是使用Dreamweaver查找相关的结束标记。看到这个链接:如何让Dreamweaver显示结束标记?

in dreamweaver:
To select matching opening and closing curly braces, brackets, or parentheses, click inside the opening or closing symbol, and click the Balance Braces button on the Coding toolbar (it's immediately below Select Parent Tag). Alternatively, use the keyboard shortcut, Ctrl+'/Cmd+'.

在dreamweaver中:要选择匹配的开始和结束花括号、括号或圆括号,请在开始或结束符号中单击,并单击编码工具栏上的Balance花括号按钮(紧接在select Parent标记下面)。或者,使用快捷键Ctrl+'/Cmd+'。

#3


1  

Komodo Edit has a nice feature that highlights what's inside braces

Komodo编辑有一个很好的特性,突出了大括号内的内容

Ctrl+Alt+]

Ctrl + Alt +)

#4


1  

I'm just working on a related problem (find missing array square bracket in JSON-object). So I hope to be able to help.

我正在处理一个相关的问题(在json对象中找到缺失的数组方括号)。所以我希望能有所帮助。

     $pos=0;
     $braceCount=0;
while( preg_match('~\{|\}~S', $source, $out, PREG_OFFSET_CAPTURE, $pos) ){
     if($out[0][0] === '{'){
       $braceCount++;
       if( $braceCount === 1 )$startPos=$out[0][1];
     }
     elseif( $out[0][0] === '}' ){
       $braceCount--;
       if( $braceCount === 0 ){
         //echo 'Up to that position:'.$out[0][1].' every thing seems to be ok?<br>';
         echo substr($source,$startPos,($out[0][1]+1-$startPos)).'<br>';
       } 
       elseif( $braceCount < 0 ){
         echo 'To many closing brace right before '.($out[0][1]+1).'<br>';
         exit;
       }
     }
     $pos = $out[0][1]+1;
}
if( $braceCount > 0 ) echo 'Closing brace is missing somewhere.'; 

This echo the source until there is a miss match and an error for curly braces.

这将回显源,直到出现一个缺失匹配和一个花括号错误。

#5


0  

What text editor are you using? I will recommend you to use Eclipse and it will be much easier to detect it :) or also you can public your code and may we can help in that way :)

你正在使用什么文本编辑器?我将建议您使用Eclipse,它将更容易检测它:)或者您也可以公开您的代码,我们可以这样帮助您:

#6


0  

Use NetBeans IDE for PHP.
http://netbeans.org/features/php/

为PHP使用NetBeans IDE。http://netbeans.org/features/php/

Will check your syntax and highlight issues amongst the many other nice features it has. And it's free.

将检查您的语法和突出问题的许多其他优秀的特性。而且它是免费的。

#7


0  

We really appreciate how smart everybody is! Sometimes its better to stick to the tool the person is using and exactly what they are asking about. I don't know if you have found your answer but here is what I use.

我们真的很欣赏每个人有多聪明!有时,最好还是坚持使用这个人正在使用的工具以及他们所询问的内容。我不知道你们是否找到了答案,但我用的是这个。

  1. Put your cursor on the opening Brace then -
  2. 把你的光标放在打开的支架上。
  3. On Mac: [Command]'
  4. 在Mac(命令):“

or Edit Menu > Balance Braces 3. Result: This will highlight the code on Dreamweaver between the braces and help resolve the coding issue.

或者编辑菜单>平衡括号3。结果:这将突出显示在花括号之间的Dreamweaver上的代码,并帮助解决编码问题。

Hope this helps. P.S. Sometimes you need 3000 lines of code :)

希望这个有帮助。有时你需要3000行代码:)

#1


2  

Use consistent and clean tabbing. I've found that makes it very hard to miss a closing brace.

使用一致和干净的表格。我发现,这让我们很难错过最后一击。

Other than that, you've kinda dug your own grave here. What are you coding that results in a 3500-line PHP file?

除此之外,你还在这里挖了自己的坟墓。您正在编写什么代码来生成一个3500行PHP文件?

EDIT: Try dumping your code into Notepad++. I'm fairly sure that will highlight the associated closing brace if you click on the opening one, but with larger files, I've gotten somewhat unreliable performance with this.

编辑:试着把你的代码放到记事本++中。我敢肯定,如果你点击打开的文件,它会突出显示相关的关闭括号,但是对于较大的文件,我已经获得了一些不可靠的性能。

#2


2  

another option (similar to notepad++) is to use Dreamweaver to find the associated closing tag.
See this link: How do I make Dreamweaver to show me closing tags?

另一个选项(类似于notepad++)是使用Dreamweaver查找相关的结束标记。看到这个链接:如何让Dreamweaver显示结束标记?

in dreamweaver:
To select matching opening and closing curly braces, brackets, or parentheses, click inside the opening or closing symbol, and click the Balance Braces button on the Coding toolbar (it's immediately below Select Parent Tag). Alternatively, use the keyboard shortcut, Ctrl+'/Cmd+'.

在dreamweaver中:要选择匹配的开始和结束花括号、括号或圆括号,请在开始或结束符号中单击,并单击编码工具栏上的Balance花括号按钮(紧接在select Parent标记下面)。或者,使用快捷键Ctrl+'/Cmd+'。

#3


1  

Komodo Edit has a nice feature that highlights what's inside braces

Komodo编辑有一个很好的特性,突出了大括号内的内容

Ctrl+Alt+]

Ctrl + Alt +)

#4


1  

I'm just working on a related problem (find missing array square bracket in JSON-object). So I hope to be able to help.

我正在处理一个相关的问题(在json对象中找到缺失的数组方括号)。所以我希望能有所帮助。

     $pos=0;
     $braceCount=0;
while( preg_match('~\{|\}~S', $source, $out, PREG_OFFSET_CAPTURE, $pos) ){
     if($out[0][0] === '{'){
       $braceCount++;
       if( $braceCount === 1 )$startPos=$out[0][1];
     }
     elseif( $out[0][0] === '}' ){
       $braceCount--;
       if( $braceCount === 0 ){
         //echo 'Up to that position:'.$out[0][1].' every thing seems to be ok?<br>';
         echo substr($source,$startPos,($out[0][1]+1-$startPos)).'<br>';
       } 
       elseif( $braceCount < 0 ){
         echo 'To many closing brace right before '.($out[0][1]+1).'<br>';
         exit;
       }
     }
     $pos = $out[0][1]+1;
}
if( $braceCount > 0 ) echo 'Closing brace is missing somewhere.'; 

This echo the source until there is a miss match and an error for curly braces.

这将回显源,直到出现一个缺失匹配和一个花括号错误。

#5


0  

What text editor are you using? I will recommend you to use Eclipse and it will be much easier to detect it :) or also you can public your code and may we can help in that way :)

你正在使用什么文本编辑器?我将建议您使用Eclipse,它将更容易检测它:)或者您也可以公开您的代码,我们可以这样帮助您:

#6


0  

Use NetBeans IDE for PHP.
http://netbeans.org/features/php/

为PHP使用NetBeans IDE。http://netbeans.org/features/php/

Will check your syntax and highlight issues amongst the many other nice features it has. And it's free.

将检查您的语法和突出问题的许多其他优秀的特性。而且它是免费的。

#7


0  

We really appreciate how smart everybody is! Sometimes its better to stick to the tool the person is using and exactly what they are asking about. I don't know if you have found your answer but here is what I use.

我们真的很欣赏每个人有多聪明!有时,最好还是坚持使用这个人正在使用的工具以及他们所询问的内容。我不知道你们是否找到了答案,但我用的是这个。

  1. Put your cursor on the opening Brace then -
  2. 把你的光标放在打开的支架上。
  3. On Mac: [Command]'
  4. 在Mac(命令):“

or Edit Menu > Balance Braces 3. Result: This will highlight the code on Dreamweaver between the braces and help resolve the coding issue.

或者编辑菜单>平衡括号3。结果:这将突出显示在花括号之间的Dreamweaver上的代码,并帮助解决编码问题。

Hope this helps. P.S. Sometimes you need 3000 lines of code :)

希望这个有帮助。有时你需要3000行代码:)