pub / rememori

Simple file-based bookmarking and notes application
git clone https://src.jayvii.de/pub/rememori.git
Home | Log | Files | Exports | Refs | README | RSS

commit ddf9ee7eb96aac357a138dc9f8f44802d14ee010
parent c2c706ceddbd026bfd8e89b48c8776a9e05ba7f6
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Fri, 25 Oct 2024 14:57:21 +0200

feat: helper function to extract link in first line of files

Diffstat:
Mlib/helpers.php | 23++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/lib/helpers.php b/lib/helpers.php @@ -1,8 +1,29 @@ <?php -function sort_by_time($a, $b) { +function sort_by_time(array $a, array $b) { // sort from oldest to newest (reversed) return $b["time"] - $a["time"]; } +function link_in_first_line(string $filepath) { + + /* read first line of file */ + $file_first_line = file($filepath, FILE_IGNORE_NEW_LINES)[0]; + + /* extract links from first line */ + $file_link = preg_replace( + '/^(http(s){0,1}:\/\/[^\s]+)*.*$/', + '\1', + $file_first_line + ); + + /* return link or false, if none was found */ + if ($file_link != "") { + return $file_link; + } else { + return false; + } + +} + ?>