mirror of
https://github.com/myvesta/vesta
synced 2025-07-05 20:41:53 -07:00
php function "find_in_file"
This commit is contained in:
parent
4563f02f0f
commit
da136faf08
2 changed files with 12 additions and 1 deletions
|
@ -12,7 +12,7 @@ define('MYVESTA_ERROR_GENERAL', 5);
|
|||
|
||||
function myvesta_throw_error($code, $message) {
|
||||
global $myvesta_exit_on_error;
|
||||
echo "ERROR: ".$message."\n";
|
||||
if ($message!=='') echo "ERROR: ".$message."\n";
|
||||
if ($myvesta_exit_on_error) myvesta_exit($code);
|
||||
return $code;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,17 @@
|
|||
|
||||
// --- file functions ---
|
||||
|
||||
function myvesta_find_in_file($file, $find) {
|
||||
if (!file_exists($file)) return myvesta_throw_error (MYVESTA_ERROR_FILE_DOES_NOT_EXISTS, "File '$file' not found");
|
||||
|
||||
$buf=file_get_contents($file);
|
||||
|
||||
$pos=strpos($buf, $find);
|
||||
if ($pos===false) return myvesta_throw_error (MYVESTA_ERROR_STRING_NOT_FOUND, "");
|
||||
|
||||
return $pos;
|
||||
}
|
||||
|
||||
function myvesta_replace_in_file($file, $find, $replace) {
|
||||
if (!file_exists($file)) return myvesta_throw_error (MYVESTA_ERROR_FILE_DOES_NOT_EXISTS, "File '$file' not found");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue