Ec (2); & lt ;? Php tutorial AskforInputfwrite (STDOUT, & quot; PleaseSelectOption (DefaultisFind) [1] Find [2] ReplacePleaseInputNumber: & quot;); GetInput $ todotrim (fgets (STDIN )); if (empty script ec (2); script
// Ask for Input
Fwrite (STDOUT, "Please Select Option (Default is Find) [1] Find [2] Replace Please Input Number :");
// Get Input
$ Todo = trim (fgets (STDIN ));
If (empty ($ todo) $ todo = 1;
If ($ todo! = 1 & $ todo! = 2 ){
Echo "Selected Error! ";
Exit;
}
If ($ todo = 1 ){
Fwrite (STDOUT, "Please Input Find Directory (Default is Current Directory ):");
$ Dir = trim (fgets (STDIN ));
If (empty ($ dir )){
$ Dir = getcwd (); // Current Directory
} Else {
If (! Is_dir ($ dir )){
Echo "Directory Not Exist! ";
Exit;
}
}
Fwrite (STDOUT, "Please Input Content of the Find :");
$ Search = trim (fgets (STDIN ));
Echo "In Directory '". $ dir. "'Find'". $ search. "', Please Wait ...";
Exec ("find ". $ dir. "-exec grep -- exclude = '*. svn /*'--'". $ search. "'{}+", $ output );
Foreach ($ output as $ val ){
Echo "$ val ";
}
} Else {// write input back
Fwrite (STDOUT, "Please Input Find Directory (Default is Current Directory ):");
$ Dir = trim (fgets (STDIN ));
If (empty ($ dir )){
$ Dir = getcwd (); // Current Directory
} Else {
If (! Is_dir ($ dir )){
Echo "Directory Not Exist! ";
Exit;
}
}
Fwrite (STDOUT, "Please Input Prefix (Default is php ):");
$ Ext = trim (fgets (STDIN ));
If (empty ($ ext) $ ext = 'php ';
Fwrite (STDOUT, "Please Input Find Content :");
$ Search = trim (fgets (STDIN ));
Fwrite (STDOUT, "Please Input Replace Content :");
$ Replace = trim (fgets (STDIN ));
Echo "directory in progress '". $ dir. "'search suffix is '". $ ext. "'file, content '". $ search. "'replace '". $ replace. "', please wait... ";
Exec ("find ". $ dir. "-name '*. ". $ ext. "'-exec sed -- in-place's /". $ search. "/$ replace/G '{};");
Echo "Replace Completed! ";
}
?>