Wednesday, August 22, 2012

Find string in all included files in PHP

Some times when debugging we find some variables or string, but when tons of php code is included its big problem. Here's how I search string or variable in all included files.
$file_included = get_included_files();

foreach($file_included as $val) {
    if(preg_match('/YOUR STRING HERE/',file_get_contents($val))){  
       echo $val.'

';
    }
}
You simply need to include that on the footer of your page

2 comments:

  1. i think this only search parth of the included filename not the content

    ReplyDelete
  2. yes, thanks fo the correction. there should be a file get contents that will read the looped file

    ReplyDelete