.*$/m', '', $markdown); // Remove multiple spaces, leading and trailing spaces $plaintext = trim(preg_replace('/\s+/', ' ', $markdown)); return $plaintext; } } if (! function_exists('markdown_min_read')) { function markdown_min_read($markdown) { return read_duration(plain_text(Markdown::convert($markdown)->getContent())); } } if (! function_exists('unslug')) { function unslug($slug, $delimiter = '-') { return ucwords(str_replace($delimiter, ' ', $slug)); } } if (! function_exists('str_slug')) { function str_slug($string, $delimiter = '-') { return Str::of(trim($string))->slug($delimiter); } } if (! function_exists('str_first_sentence')) { function str_first_sentence($str) { // Split the string at ., !, or ? but include these characters in the match $sentences = preg_split('/([.!?])\s/', $str, 2, PREG_SPLIT_DELIM_CAPTURE); // Check if we have captured the first sentence and its punctuation if (isset($sentences[0]) && isset($sentences[1])) { return trim($sentences[0].$sentences[1]); } // If no sentence ending found, return the whole string return $str; } } if (! function_exists('is_empty')) { /** * A better function to check if a value is empty or null. Strings, arrays, and Objects are supported. * * @param mixed $value */ function is_empty($value): bool { if (is_null($value)) { return true; } if (is_string($value)) { if ($value === '') { return true; } } if (is_array($value)) { if (count($value) === 0) { return true; } } if (is_object($value)) { $value = (array) $value; if (count($value) === 0) { return true; } } return false; } } if (! function_exists('get_country_name_by_iso')) { function get_country_name_by_iso($country_iso) { if (! is_empty($country_iso)) { $country_iso = strtoupper($country_iso); try { return config("platform.country_codes.{$country_iso}")['name']; } catch (\Exception $e) { } } return 'International'; } } if (! function_exists('get_country_emoji_by_iso')) { function get_country_emoji_by_iso($country_iso) { if (! is_empty($country_iso)) { $country_iso = strtoupper($country_iso); try { return config("platform.country_codes.{$country_iso}")['emoji']; } catch (\Exception $e) { } } return '🌎'; } } if (! function_exists('str_random')) { function str_random($length = 10) { return Str::random($length); } }