<?php Tutorial
Ask for Input
Fwrite (STDOUT, "" Please select Option (Default are 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 to find directory (Default are 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." ";
EXEC ("Find" $dir. "-exec grep--exclude= ' *.svn/* '--'". $search. "' {} + ", $output);
foreach ($output as $val) {
echo "$val";
}
}else{//Write input back
Fwrite (STDOUT, "please Input to find directory (Default are 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 "is in Catalog". $dir. "' Find suffix ' ". $ext." ' file, the content ' ". $search." ' Replace with ' ". $replace." ', please later ... ";
EXEC ("Find" $dir. "-name ' *.". $ext. "' -exec sed--in-place ' s/'. $search. " /$replace/g ' {}; ");
echo "Replace completed!";
}
?>