Untitled
raw download clone
PHP
views 24
,
size 1008 b
function formatText($title, $shorten = 0, $strip_tags = false) {
	$title = jsonLangText($title);

	if ($strip_tags) {
		$tag2s_arr = array("</p>", "</ul>", "</ol>", "</li>");
		$title = str_replace($tag2s_arr, " ", $title);

		$tag2e_arr = array("<p>", "<ul>", "<ol>", "<li>");
		$title = str_replace($tag2e_arr, " ", $title);

		$title = strip_tags($title);
	}

	# misc correction
	$title = str_replace("el.pa", "el. pa", $title);

	$title = preg_replace('{\?+}', '?', $title);
	$title = preg_replace('{\!+}', '!', $title);
	$title = preg_replace("/\s+/", " ", $title);
	$title = trim($title);

	if ($shorten > 0)
		$title = mb_strimwidth($title, 0, $shorten, '...', 'utf-8');

	if (mb_strtoupper($title, 'utf-8') == $title) {
		$title = preg_replace_callback('/([.!?])\s*(\w)/', function ($matches) {
			return mb_strtoupper($matches[1] . ' ' . $matches[2]);
		}, ucfirst(mb_strtolower($title)));
	}

	$title = myucfirst($title);
	$title = trim($title);

	return $title;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.