Welcome Guest, Not a member yet? Register   Sign In
Find - IfFound - IfNotFound in CodeIgniter
#3

(This post was last modified: 09-01-2019, 10:07 AM by Wouter60.)

Put the contents of each file in a string.
Use strstr() or stristr() to search for text in that string.
If strstr() or stristr() returns false, then the text wasn't found.

Besides that, put the files you need to search in an array and use a loop to check all files.

Example:
PHP Code:
$found false;
$this->load->helper(array('directory','file'));
$filenames directory_map('./mydirectory/');
foreach (
$filenames as $filename) {
  $filetext read_file('./mydirectory/' $filename);
  if (stristr($filetext,'abc')) {
      $found true;
      $found_in $filename;
      break;  //exit the foreach loop
  }
}
if (
$found) {
  echo 'The string "abc" was found in ' $found_in;
}
else {
  echo 'The string "abc" was not found in any file in ./mydirectory/';

Reply


Messages In This Thread
RE: Find - IfFound - IfNotFound in CodeIgniter - by Wouter60 - 09-01-2019, 06:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB