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

(This post was last modified: 09-03-2019, 08:52 AM by Wouter60.)

OK, I've found some time to explain a few things.

directory_map is a helper function which will return the filenames in a given directory.
If you already know the filenames, it's easier to do this:
PHP Code:
$file1 'C:\\xampp\\htdocs\\file1\\name.php'
On a Windows file system, you must escape the backslashes!

If you have more than one file to perform the same type of actions on, I would prefer an array (like in my example). Otherwise, you'll have to write a lot of repetitive code.
One of the principles of programming is: DRY (don't repeat yourself).

To make an array of the files you want to search:
PHP Code:
$filenames = array(
  'C:\\xampp\\htdocs\\file1\\name.php',
  'C:\\xampp\\htdocs\\file2\\name.php',
  'C:\\xampp\\htdocs\\file3\\name.php',
  'C:\\xampp\\htdocs\\file4\\word.php',
); 

To prevent an error message: Undefined variable: found
make sure you define the variable $found before you do anything else.
That's why I put it at the beginning of my code block:
PHP Code:
$found false;  //if nothing happens, $found has the initial value false 

It's not logical at all (and bad practice) to set $found to false if the value you are looking for, is found.
Set it to true if the result is positive, or false if the result is negative. Not the other way around.

You have this line of code:
PHP Code:
if (strstr($filetext,'$name')) 
This will return a result if the literal string '$name' (with dollar sign!) occurs in the $filetext string.
If $name is meant as a variable, don't use quotes around it. But remember: the $name variable should be defined before you use it!
Reply


Messages In This Thread
RE: Find - IfFound - IfNotFound in CodeIgniter - by Wouter60 - 09-03-2019, 08:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB