All pastes #832718 Raw Edit

Someone

public text v1 · immutable
#832718 ·published 2007-12-26 14:51 UTC
rendered paste body
function securify($text, $cap = 0, $trim = 1, $paranoid = 1, $news = 0) {
	global $DBc;
	
	if ($news == 1) {
		// We need some html tags for the news
		$text = strip_tags($text, "<p> <i> <b> <a> <img>");
	} else {	
		if ($paranoid == 1) {
			// Get rid of tags and quotes
			$text = htmlentities($text, ENT_QUOTES, 'UTF-8');
		} elseif ($paranoid == 2) {
			// just strip all tags for saving to db
			$text = strip_tags($text);
		}	else {
			// Leave quotes alone
			$text = htmlentities($text, ENT_NOQUOTES, 'UTF-8');
		}
	}

	if ($cap == 1) {
		// Capitalise the first word of every string
		$text = ucwords($text);
	}

	// replace the lf & cr tags to the  <br /> tag
	$text = nl2br($text);

	if (get_magic_quotes_gpc()) {
		// Stripslashes if magic quotes are on (really shouldn't be though)
    	$text = stripslashes($text);
	}
	
	// Escape mysql special chars
  $text = mysqli_real_escape_string($DBc, $text);
  
  if ($trim == 1) {
  	//Cut off empty spaces at the beginning and end
		//remove double spaces
		$text = ereg_replace("/\s{1,}/", " ", trim($text));
	}
	
	if ($news == 1) {
		//replace nicknames with the right case
		$text = str_replace("SL", "sL", $text);
	}
	return $text;
}