note 12732 deleted from function.eregi-replace by jimw

From: Date: Fri, 02 Nov 2001 02:07:00 +0000
Subject: note 12732 deleted from function.eregi-replace by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-20241@lists.php.net to get a copy of this message
I found this usefull: <?php // Uli Pahlke " www.screengraphics.de " ========================== // function to cleanup textinputs & textareas // wraps strings after a specified stringlength if ask for $textinput = "1234567890"; $textinput .= "abcdefghijklmnopqrstuvwxyz"; $textinput .= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $textinput .= "\&\!\$\%\\/\(\)\=\?\`\*\'\<\>\;\:\_"; $textinput .= "\{\[\]\}\\\~\|"; $textinput .= "\""; // test ---------------------------------------------------------- echo "<b>Original:</b><br> ".stripslashes($textinput)."<br>"; // function starts here ----------------------------------------- function cleanup($textinput,$cleanup="0",$wrapspace_after="5000"){ // $textinput == StringSource / z.B.: textfelder, textareas usw. // $cleanup == 0 only digits & letters allowed (default = 0) // $cleanup == 1 only letters allowed // $cleanup == 2 only digits allowed // $cleanup == 3 no spaces // $wrapspace_after == wraps strings after a specified stringlength if ask for (default = 5000) // bei $cleanup == 3 / no wrapping if ($cleanup == 0){ $clean = eregi_replace ("[[:punct:]]","",$textinput); $wrapped = wordwrap( $clean,$wrapspace_after,"\n",1); } elseif ($cleanup == 1){ $clean = eregi_replace ("[[:digit:][:punct:]]","",$textinput); $wrapped = wordwrap( $clean,$wrapspace_after,"\n",1); } elseif ($cleanup == 2){ $clean = eregi_replace ("[[:alpha:][:punct:]]","",$textinput); $wrapped = wordwrap( $clean,$wrapspace_after,"\n",1); } elseif ($cleanup == 3){ $clean = trim(eregi_replace("[[:space:]]", "" , $textinput)); } if($cleanup == 3){ return stripslashes($clean); } else { $clean = $wrapped; return stripslashes($clean); } } // function ends here ------------------------------------------- //call function = cleanup($textinput,0,5000); // test ---------------------------------------------------------- echo "<br><b>Clean:</b><br> ".cleanup($textinput,0,5000); ?> Have Fun - Uli

« previous php.notes (#20241) next »