filter_var

Have a good idea ? Want to suggest something ? Have a couple of lines of code to back it up ?
Post it here !

filter_var

Postby solarix on 28-03-2010 18:18

I am running 0.8.2 and have an issue with filter_var. It is not in the PHP that I use and I can not update php on this aging machine. Everything else seems to work OK.

Can someone assist me in a possible rewrite of this section of code?
function my_filter_var($s,$filter_type = FILTER_SANITIZE_STRING) { // 0.8.2: PREG_REPLACE vanishes in new versions of PHP...use filter_var instead:
$s=filter_var($s,$filter_type,FILTER_FLAG_STRIP_LOW);
$s=filter_var($s,$filter_type,FILTER_FLAG_STRIP_HIGH);
return $s;
}

The offending lines are the filter_var lines. Seems to me it could be done with PREG_REPLACE but I can not figure it out.

Thanks,

Jerry
solarix
Newbie
Newbie
 
Posts: 1
Joined: 28-03-2010 18:11

Re: filter_var

Postby Michael on 06-04-2010 16:52

Hi Jerry,

Welcome to the AmpJuke forum and thanks for posting.

preg_replace..?
Well, it would be something like this:
Code: Select all
function my_filter_var($s) {
return preg_replace ("/[^0-9^a-z^A-Z^_^.^ ^#]/", "", $s);
}


...cannot guarantee 100% it's gonna work right away, but at least the aboe preg_replace statement will (should) get rid of anything but a-z, A-Z, 0-9,_,. and #.

Hope this makes sense. If not, please post an update (well, feel free to do so in any case).

//Michael.
User avatar
Michael
Site Admin
Site Admin
 
Posts: 449
Joined: 03-07-2007 13:46
Location: Denmark


Return to Requests / suggestions

Who is online

Users browsing this forum: No registered users and 1 guest

cron