Zend - The PHP Company




Text

Add Code


StringCleanUp Function  

Type: code fragment
Added by: UliPahlke
Entered: 02/05/2001
Last modified: 05/12/2000
Rating: - (fewer than 3 votes)
Views: 5608
CleanUp strings (textfields, textareas)


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

?>


Usage Example




Rate This Script





Search



This Category All Categories