From da136faf08b8cc83b8532cd04fe3fae53bb3b6ef Mon Sep 17 00:00:00 2001 From: myvesta <38690722+myvesta@users.noreply.github.com> Date: Sun, 26 Mar 2023 19:04:45 +0200 Subject: [PATCH] php function "find_in_file" --- func/main.php | 2 +- func/string.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/func/main.php b/func/main.php index 1a932fa71..cf13f3f01 100644 --- a/func/main.php +++ b/func/main.php @@ -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; } diff --git a/func/string.php b/func/string.php index 3882c069c..2b6a63d95 100644 --- a/func/string.php +++ b/func/string.php @@ -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");