Jump to content

Using htmlpurifier with foreach


happypete

Recommended Posts

Hi,

 

I have a photo gallery that I was updating with the following code, but want to implement the htmlpurifier instead

 

// Update galley title and orders
	 $sql = "UPDATE photos SET description=?, rank=? WHERE id=? AND siteid=?";
		$stmt = $db->prepare($sql);

		if(count($_POST['rank']) > 0)
		{
		  foreach($_POST['rank'] AS $key => $val)
		  {
		    $stmt->execute(array(
			htmlentities(str_replace(array('/iframe', '/script'), '', $_POST['description'][$key])), $val, $key, $siteid)
			);
		  }
		}

 

I need to use htmlpurifier on each $_POST['description'] but haven't got a clue how to implement it.

 

        require ('htmlpure/HTMLPurifier.standalone.php');

$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);
$clean_html1 = $purifier->purify(stripslashes($_POST['description']));

 

Do I need to put the '$_POST['description']' into an array first to apply the htmlpurifier, if so how do I go about doing that?

Link to comment
https://forums.phpfreaks.com/topic/268329-using-htmlpurifier-with-foreach/
Share on other sites

Solved it. I added the following:

 


require ('htmlpure/HTMLPurifier.standalone.php');
$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);

// purify each description
	foreach ($_POST['description'] AS $key=>$val)
	{
	$_POST['description'][$key] = $purifier->purify($val);
	};

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.