Func f1($arg1,$arg2) ; start of function )<
Func f2() ; !!! func f3 blah blah
	   Func f1($arg1,$arg2) ; start of function
	       Func 	f2() ; !!! func f3()?? blah blah
RegularLineofCodeWithFunc()
; Another Line of Code with Func f1()
Function Start?
While $RunFunction = 1 ;this is the line that caused trouble with your script
fUnc f3($RunFunction)
FUNC f4($RunFunction = 1)
How about this line? Is it a Func funcname($argument)? Or is it correctly seen as a regular line?
EndFunc
EndFunc ;==>end of f1 ;D
    EndFunc ; this one has whitespace at the start
	EndFUNC ; this one has a tab and mixed case
		EndfUnc ; this one has two tabs and mixed case
	   Endfunc ;==> End of function
; Endfunc ; End of function with invalid code preceding it
$str = "EndFunc" ; This isn't the end of a function, but your code thinks it is, since you're only
; checking if Func/EndFunc is in the string, and not the actual validity of the string.
Func ; this is an invalid function
Func f5 ; this is another invalid function
Func  f6	 (	) ; this is a valid function full of spaces and tabs
	Func f7 ( ; no matching end bracket