💥 Ajoute les tags en base et les formate

Pour #1
This commit is contained in:
2019-09-30 16:32:40 +02:00
parent a7715c8460
commit a9cd4ed610
7 changed files with 112 additions and 9 deletions

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Services;
class TagDetectorService
{
public const REGEX_FIND = '/\s#([^\s]+)(?:\s|$)/m';
public const REGEX_REPLACE = '/\s(#[^\s]+)(?:\s|$)/m';
/**
* @param string $text
*
* @return array
*/
public function detectFrom($text)
{
if (preg_match_all(self::REGEX_FIND, $text, $tags) !== false) {
return $tags[1];
}
return [];
}
/**
* @param string $text
*
* @return string|string[]|null
*/
public function linkTagFrom($text)
{
return preg_replace(
self::REGEX_FIND, str_replace('$1', '$1', sprintf(' <a href="%s/%s">%s</a> ', url('stats'), '$1', '#$1')),
$text
);
}
}