You are here: clean double spaces and returns from input boxes and textarea « PHP Language « IT news, forums, messages
clean double spaces and returns from input boxes and textarea

Posted by Gleep on 04/19/07 19:07

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("/&#032&#032+/", " ", $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>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация