Files
2026-06-04 11:13:34 +01:00

40 lines
1005 B
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
class Text {
private $text;
public function __construct($text) {
if (!$text) {
$text = "";
}
$this->text = $this->cleanup($text);
}
function cleanup($text) {
$text = str_replace(" ", " ", $text);
$text = str_replace("\t", " ", $text);
$text = str_replace("\r", " ", $text);
$text = str_replace("\n", " ", $text);
$text = str_replace("\"", "", $text);
$text = str_replace(",", " ", $text);
$text = str_replace("", "-", $text);
$text = str_replace("—", "-", $text);
$text = str_replace("Ø", "0", $text);
$text = str_replace("~", "-", $text);
$text = str_replace("--", "-", $text);
$text = preg_replace('/\s\s+/', ' ', $text);
return trim($text);
}
public function get_text() {
return $this->text;
}
public function words() {
$text = preg_replace('/([^A-Z\-0-9]+)/', ' ', strtoupper($this->text));
$words = preg_split('/\s+/', $text);
return $words;
}
}