For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > April 2007 > clean double spaces and returns from input boxes and textarea









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author clean double spaces and returns from input boxes and textarea
Gleep

2007-04-19, 6:58 pm

Hope this function is usefull


<?php
// cleans up input boxes/textareas, trim ends, removes html, double spaces and multi returns
function clean($ob) {
$x = trim($ob);
$x = strip_tags($x);
$x = preg_replace("/ +/", " ", $x);
$x = preg_replace("/[\r\t\n]{3,}/","\n\n", $x);
return $x;
}

$sample = clean($_POST['sample']);
echo nl2br($sample);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>clean test</title>
</head>
<body>
<form id="FormName" action="<?=$PHP_SELF?>" method="post" name="FormName">
<textarea name="sample" rows="10" cols="40"></textarea>
<p><input type="submit" name="Submit" value="Submit" /></p>
</form>
</body>
</html>
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com