Sync
This commit is contained in:
@@ -1,11 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
if (! function_exists('epoch_now_timestamp')) {
|
||||
function epoch_now_timestamp()
|
||||
if (! function_exists('dmy')) {
|
||||
function dmy(Carbon $carbon)
|
||||
{
|
||||
return (int) round(microtime(true) * 1000);
|
||||
|
||||
return $carbon->format('d M Y');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('epoch_now_timestamp')) {
|
||||
function epoch_now_timestamp($multiplier = 1000)
|
||||
{
|
||||
return (int) round(microtime(true) * $multiplier);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('add_params_to_url')) {
|
||||
function add_params_to_url(string $url, array $newParams): string
|
||||
{
|
||||
$url = parse_url($url);
|
||||
parse_str($url['query'] ?? '', $existingParams);
|
||||
|
||||
$newQuery = array_merge($existingParams, $newParams);
|
||||
|
||||
$newUrl = $url['scheme'].'://'.$url['host'].($url['path'] ?? '');
|
||||
if ($newQuery) {
|
||||
$newUrl .= '?'.http_build_query($newQuery);
|
||||
}
|
||||
|
||||
if (isset($url['fragment'])) {
|
||||
$newUrl .= '#'.$url['fragment'];
|
||||
}
|
||||
|
||||
return $newUrl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,6 +206,34 @@ function str_first_sentence($str)
|
||||
|
||||
}
|
||||
|
||||
if (! function_exists('str_extract_sentences')) {
|
||||
function str_extract_sentences($str, $count = 1)
|
||||
{
|
||||
// Split the string at ., !, or ?, including the punctuation in the result
|
||||
$sentences = preg_split('/([.!?])\s*/', $str, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
$extractedSentences = [];
|
||||
$currentSentence = '';
|
||||
|
||||
foreach ($sentences as $key => $sentence) {
|
||||
if ($key % 2 == 0) {
|
||||
// This is a sentence fragment
|
||||
$currentSentence = $sentence;
|
||||
} else {
|
||||
// This is a punctuation mark
|
||||
$currentSentence .= $sentence;
|
||||
$extractedSentences[] = trim($currentSentence);
|
||||
|
||||
if (count($extractedSentences) >= $count) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $extractedSentences;
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('unslug')) {
|
||||
function unslug($slug, $delimiter = '-')
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user