note 87562 deleted from function.htmlspecialchars by danbrown

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: nessthehero at gmail dot com 

----

Here's a simple function I wrote for parsing form data.

It checks if it's an array and it is recursive (it calls itself).

It also decodes things that have already been encoded so it doesn't change &amp; to &amp;amp;

<?php

function formspecialchars($var)
	{
		if (is_array($var)) {
			$out = array();
			foreach ($var as $key => $v) {
				$out[$key] = formspecialchars($v);
			}
		} else {
			$out = htmlspecialchars_decode($var);
			$out = htmlspecialchars(stripslashes(trim($out)), ENT_QUOTES);
		}
		
		return $out;
	}

?>

I encourage people to improve upon this for other purposes! All I use it for is cleaning up form data, hence the name of the function.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.