From 212b59a6a53b285003eb87bf5229f3ff63513399 Mon Sep 17 00:00:00 2001 From: Mohamad Damaj Date: Fri, 23 Jun 2023 12:00:43 +0300 Subject: [PATCH] fix a bug --- site/blog/index.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/site/blog/index.php b/site/blog/index.php index 14a148b..cc67f98 100644 --- a/site/blog/index.php +++ b/site/blog/index.php @@ -32,8 +32,18 @@ foreach ($xml->channel->item as $item) { // Split the content into sentences $sentences = preg_split('/(?<=[.?!])\s+(?=[a-z])/i', $item->description); - // Add all the sentences of the content - $preview = implode(' ', $sentences); + // Extract the first 5 sentences of the content + $preview = implode(' ', array_slice($sentences, 0, 5)); + + // Add three dots at the end of the preview, if necessary + if (count($sentences) > 5) { + $last_char = substr($preview, -1); + if ($last_char != '.') { + $preview .= '...'; + } else { + $preview .= '..'; + } + } echo $preview; @@ -42,7 +52,7 @@ foreach ($xml->channel->item as $item) { echo '
Read more'; } - // Close the box around the article + // Close the box around the post echo ''; } ?>