mirror of
https://github.com/standardebooks/web.git
synced 2025-07-13 10:02:02 -04:00
Initial commit
This commit is contained in:
commit
28c8a3f0ba
136 changed files with 13350 additions and 0 deletions
29
lib/Formatter.php
Normal file
29
lib/Formatter.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?
|
||||
class Formatter{
|
||||
public static function MakeUrlSafe(string $text): string{
|
||||
// Remove accent characters
|
||||
$text = @iconv('UTF-8', 'ASCII//TRANSLIT', $text);
|
||||
|
||||
// Trim and convert to lowercase
|
||||
$text = mb_strtolower(trim($text));
|
||||
|
||||
// Remove apostrophes
|
||||
$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);
|
||||
|
||||
// Then convert any instance of one or more space to dash
|
||||
$text = preg_replace('/\s+/ius', '-', $text);
|
||||
|
||||
// Finally, trim dashes
|
||||
$text = trim($text, '-');
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
public static function ToPlainText(string $text): string{
|
||||
return htmlspecialchars(trim($text), ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue