In the first post I will tell you how to find some text inside directories and sub directories
using php scripting engine.
case:
Suddenly i need to replace my script to featin new project that containt new keyword.
sadnews that I have more than 50 file to replace in folder and subfolder.
I think How can I automate this process?
solution:
I have idea to find that file containt keywords then replace text using PHP-script, write new content
and loop inside folder and sub folder
algorithm:
1. opendir folder using default php function opendir()
2. loop readdir using php function readdir()
3. read current entire file using php function fopen(), fread() , filesize(), fclose()
4. search entire content using php regexp function eregi()
5. if keywords found then i goto next step, if not then I goback loop to step 2
6. if found then i replace keyword string in old content and make new content using
php function str_replace()
7. write new content to file using , fopen(), fwrite(), fclose()
practical:
step1 , we need to define which is start folder
and what is keywords and what is replace string
in code above I must replace \ (slash) with / (backslash) that make php more easy to read folder
step 2, make function my_replace_content
the reason i make this function is if we detect file is folder then we can call this function again
and recursivelly read entire dir.
$folderparam is parameter that we can capture from last call
step 3 and next, add opendir and loop with readdir function to read entire dir and soo on
next step, fullsource code that we can write:
last step, implementation in cmd shell:
clic start-> run -> type : cmd , then pres [enter button]
c:\>c:\apache\php\php.exe -q c:\replacestring.php