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
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);
	};

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.