PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Could really do with some help on this as I'm quite confused.
I want to insert HTML from a within textarea tags in a form into a mysql database. I've tried mysql_escape_string() and addslashes() but I'm still getting an error.
The variables $content, $questions and $marking_guide contain the HTML and text as well.
function PrepForDisplay()
{
// This search and replace finds the text 'x@y' and replaces
// it with HTML entities, this provides protection against
// email harvesters
static $search = array('/(.)@(.)/se');
static $replace = array('"&#" .
sprintf("%03d", ord("\\1")) .
";@&#" .
sprintf("%03d", ord("\\2")) . ";";');
$resarray = array();
foreach (func_get_args() as $ourvar) {
// Prepare var
$ourvar = htmlspecialchars($ourvar);
$ourvar = preg_replace($search, $replace, $ourvar);
// Add to array
array_push($resarray, $ourvar);
}
// Return vars
if (func_num_args() == 1) {
return $resarray[0];
} else {
return $resarray;
}
}
/**
* ready database output
* Gets a variable, cleaning it up such that the text is
* stored in a database exactly as expected
*
* @param var $ variable to prepare
* @param $ ...
* @return mixed prepared variable if only one variable passed
* in, otherwise an array of prepared variables
*/
function PrepForStore()
{
$resarray = array();
foreach (func_get_args() as $ourvar) {
if (!get_magic_quotes_runtime() && !is_array($ourvar)) {
$ourvar = addslashes($ourvar);
}
// Add to array
array_push($resarray, $ourvar);
}
// Return vars
if (func_num_args() == 1) {
return $resarray[0];
} else {
return $resarray;
}
}