Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Josh http://sabotagemedia.com

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

BBCode

Format BBCode input

function bbcode_format($var) {
	$search = array(
		'/\[b\](.*?)\[\/b\]/is',                                
		'/\[i\](.*?)\[\/i\]/is',                                
		'/\[u\](.*?)\[\/u\]/is',
		'/\[img\](.*?)\[\/img\]/is',
		'/\[url\](.*?)\[\/url\]/is',
		'/\[url\=(.*?)\](.*?)\[\/url\]/is'
		);

	$replace = array(
		'<strong>$1</strong>',
		'<em>$1</em>',
		'<u>$1</u>',
		'<img src="$1" />',
		'<a href="$1">$1</a>',
		'<a href="$1">$2</a>'
		);

	$var = preg_replace ($search, $replace, $var);

	return $var;
}

MySQL error reporting

MySQL error reporting

$result = mysql_query($query) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());

makeSafe

Make data safe...among other things

function makeSafe($variable) {
	$variable = htmlentities($variable, ENT_QUOTES);
  	
	if (get_magic_quotes_gpc()) { 
		$variable = stripslashes($variable); 
	}
  	
	$variable = mysql_real_escape_string(trim($variable));
 	$variable = strip_tags($variable);
	$variable = str_replace("\r\n", "", $variable);
 	
	return $variable;
}
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS