From 526d8104068f931bea85b7ae1f2541ce90540571 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 10 Apr 2024 17:25:15 +0300 Subject: [PATCH] return match line number as the array key in result --- src/Gemtext/Body.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Gemtext/Body.php b/src/Gemtext/Body.php index 5e18fd0..fabac2d 100644 --- a/src/Gemtext/Body.php +++ b/src/Gemtext/Body.php @@ -20,11 +20,11 @@ class Body { $matches = []; - foreach ($this->_lines as $line) + foreach ($this->_lines as $index => $line) { if (preg_match('/^#([^#]+)/', trim($line), $match)) { - $matches[] = trim( + $matches[$index] = trim( $match[1] ); } @@ -37,11 +37,11 @@ class Body { $matches = []; - foreach ($this->_lines as $line) + foreach ($this->_lines as $index => $line) { if (preg_match('/^##([^#]+)/', trim($line), $match)) { - $matches[] = trim( + $matches[$index] = trim( $match[1] ); } @@ -54,11 +54,11 @@ class Body { $matches = []; - foreach ($this->_lines as $line) + foreach ($this->_lines as $index => $line) { if (preg_match('/^###([^#]+)/', trim($line), $match)) { - $matches[] = trim( + $matches[$index] = trim( $match[1] ); } @@ -71,11 +71,11 @@ class Body { $matches = []; - foreach ($this->_lines as $line) + foreach ($this->_lines as $index => $line) { if (preg_match('/^=>(.*)/', trim($line), $match)) { - $matches[] = trim( + $matches[$index] = trim( $match[1] ); } @@ -88,11 +88,11 @@ class Body { $matches = []; - foreach ($this->_lines as $line) + foreach ($this->_lines as $index => $line) { if (preg_match('/' . $protocol . ':\/\/(.*)[\s\S\'"]*/', trim($line), $match)) { - $matches[] = + $matches[$index] = sprintf( '%s://%s', $protocol,