40 lines
1005 B
PHP
40 lines
1005 B
PHP
<?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;
|
||
}
|
||
}
|