mirror of
https://github.com/standardebooks/web.git
synced 2025-07-10 00:30:28 -04:00
Updates to more strict type checking after some static analysis
This commit is contained in:
parent
152f86d616
commit
c879dcab34
10 changed files with 50 additions and 34 deletions
|
@ -2,19 +2,19 @@
|
|||
class Formatter{
|
||||
public static function MakeUrlSafe(string $text): string{
|
||||
// Remove accent characters
|
||||
$text = @iconv('UTF-8', 'ASCII//TRANSLIT', $text);
|
||||
$text = iconv('UTF-8', 'ASCII//TRANSLIT', $text) ?: '';
|
||||
|
||||
// Trim and convert to lowercase
|
||||
$text = mb_strtolower(trim($text));
|
||||
|
||||
// Remove apostrophes
|
||||
$text = preg_replace("/['’]/ius", '', $text);
|
||||
$text = preg_replace("/['’]/ius", '', $text) ?: '';
|
||||
|
||||
// Then convert any non-digit, non-letter character to a space
|
||||
$text = preg_replace('/[^0-9a-zA-Z]/ius', ' ', $text);
|
||||
$text = preg_replace('/[^0-9a-zA-Z]/ius', ' ', $text) ?: '';
|
||||
|
||||
// Then convert any instance of one or more space to dash
|
||||
$text = preg_replace('/\s+/ius', '-', $text);
|
||||
$text = preg_replace('/\s+/ius', '-', $text) ?: '';
|
||||
|
||||
// Finally, trim dashes
|
||||
$text = trim($text, '-');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue