Re: [PHP] Functions
by Amit Arora other posts by this author
Jul 13 2006 3:29PM messages near this date
Re: [PHP] Functions
|
Re: [PHP] Functions
Hi,
You might wanna try something like this:
function cleaner($var)
{
$var = trim($var);
$var = strip_tags($var);
$var = ucfirst($var);
$var = addslashes($var);
// This line is not required $var = str_replace ("$","",$var);
return ($var)
}
And to actually use this function you will have to use something like this.
$var = cleaner($var);
Regards,
Amit Arora
www.digitalamit.com
benc11@[...].com wrote:
> I was able to get the return to work but not the pass in the reference.
> One
> last question, what if I want to have each item on a separate line like:
>
> function cleaner($var)
> {
> trim($var);
> strip_tags($var);
> ucfirst($var);
> addslashes($var);
> str_replace ("$","",$var);
> }
>
> $var = "abc's";
> echo $var;
>
> How would I return the results here, I tried various different ways none of
> them worked?
>
>
>
> On 6/29/06, Chris <dmagick@[...].com> wrote:
> >
> > benc11@[...].com wrote:
> > > I am trying to create a function to clean up variables that are user
> > > inputted from a form. I am not getting this script to work. Can
> > anyone
> > > help.
> > >
> > > ---Start Script---
> > > function cleaner($var)
> > > {
> > > trim(strip_tags(ucfirst(addslashes($var))));
> > > }
> > >
> > > $var = "abc's";
> > >
> > > echo $var;
> >
> >
> > You need to return the value from the function:
> >
> > return trim(strip_tags(.....)
> >
> > or pass in a reference:
> >
> > function cleaner (&$var)
> >
> >
> > --
> > Postgresql & php tutorials
> > http://www.designmagick.com/
> >
>
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Thread:
Benc11@Gmail.Com
Richard Lynch
Gerry D
Richard Lynch
Chris
Benc11@Gmail.Com
Amit Arora
Stut
John Meyer
|