Skip to content

Instantly share code, notes, and snippets.

@mooror
Last active May 14, 2020 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mooror/e647312cff315d8d9ca66205c496c443 to your computer and use it in GitHub Desktop.
Save mooror/e647312cff315d8d9ca66205c496c443 to your computer and use it in GitHub Desktop.
PHP Debugging REGEX Strings
*** ADD DEBUG LINES ***
+ CALL ONLY DEBUG
Use the following snippet to add a debug "call" line to every method in a file.
Search:
((( )*)(public|private) (static )?function (__)?([a-zA-Z0-9]*)\(.*\)\n?(\s*)\{)
Replace:
$1\n$2 print(__FUNCTION__." call (".basename(__FILE__, ".php").":".__LINE__.")\\n<br />");
+ METHOD WITH PARAMS
Search:
(((?: )*)(?:public|private) (?:static )?function (?:__)?(?:[a-zA-Z0-9]*)\((?:(?:[a-z_A-Z0-9]* )?(\$[a-zA-Z0-9_]*)(?:[="\sa-zA-Z0-9]*)?,?)?(?:(?:[a-z_A-Z0-9]* )?(\$[a-zA-Z0-9_]*)(?:[="\sa-zA-Z0-9]*)?,?)?(?:(?:[a-z_A-Z0-9]* )?(\$[a-zA-Z0-9_]*)(?:[="\sa-zA-Z0-9]*)?,?)?(?:(?:[a-z_A-Z0-9]* )?(\$[a-zA-Z0-9_]*)(?:[="\sa-zA-Z0-9]*)?,?)?(?:(?:[a-z_A-Z0-9]* )?(\$[a-zA-Z0-9_]*)(?:[="\sa-zA-Z0-9]*)?,?)?(?:(?:[a-z_A-Z0-9]* )?(\$[a-zA-Z0-9_]*)(?:[="\sa-zA-Z0-9]*)?,?)?(?:(?:[a-z_A-Z0-9]* )?(\$[a-zA-Z0-9_]*)(?:[="\sa-zA-Z0-9]*)?,?)?(?:(?:[a-z_A-Z0-9]* )?(\$[a-zA-Z0-9_]*)(?:[="\sa-zA-Z0-9]*)?,?)?\)\n?(?:\s*)\{)
Replace:
WARNING: Will not work with functions that accept objects that cannot be converted to a string
$1\n$2print(__FUNCTION__."($3 $4 $5 $6 $7 $8 $9 $10) call on line ".__LINE__."\\n<br />");
*** REMOVE DEBUG LINES ***
To remove the debug line use the following search and replace
Search:
([\n\r\s])*print\(__FUNCTION__\." called on line "\.__LINE__\."\\n<br />"\);
Replace:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment