...

View Full Version : Resolved what to use instead of filter?



low tech
11-10-2010, 04:10 PM
Hello all

I have this probelm

I input Chinese text to send to DB

but this php code is used


$data[$key] = filter($value);

and the filter is trashing the chinese

when I remove 'filter' --- the chinese is ok

is there anything else I can use instead of 'filter' that hopefully will leave the chinese intact?

any suggestion(s) appreciated
LT

kbluhm
11-10-2010, 04:33 PM
There is no native filter() in PHP, so we will need to see some code. Would you be able to find the function's definition within the app and paste it here?

low tech
11-11-2010, 12:57 AM
Hi all

and thank you kbluhm

yeh it was late when I posted and after reading your reply I realised I made a small mistake

this is the code I should have posted


////////// Filter POST data for harmful code (sanitize)
foreach($_POST as $key => $value) {
$data[$key] = $filter($value);
}

and now I see that filter is a variable so I need to track that down

I'll post back once I find it if I can't resolve it

thank you

LT

Keleth
11-11-2010, 01:02 AM
That... makes no sense? If its a variable, why parens after it? Admittedly, my experience is limited, but won't that result in an error?

kbluhm
11-11-2010, 01:20 AM
It'd be a variable function name:


$fetch = 'mysql_fetch_assoc';

$row = $fetch( $result );

So based on the possible values of $filter, there may be multiple pieces of code to debug.

Keleth
11-11-2010, 01:24 AM
It'd be a variable function name:


$fetch = 'mysql_fetch_assoc';

$row = $fetch( $result );

So based on the possible values of $filter, there may be multiple pieces of code to debug.

Ah... didn't know you could do that... and explains a lot of errors I've gotten... and can actually make my life a lot easier... hm...

low tech
11-11-2010, 01:26 AM
Hi all

Thanks for response

seems I got mixed up again --- so not my day

anyway Keleth I think you are right it makes no sense --- it not a variable thats my mistake ---- I posted correctly last night and wrongly this morning der on me

anyway

I found this function which should now make sense to everything



function filter($data) {
$data = trim(htmlentities(strip_tags($data)));

if (get_magic_quotes_gpc())
$data = stripslashes($data);

$data = mysql_real_escape_string($data);

return $data;
}

This is what is killing the Chinese:-)

I need to clean the text input area and still keep Chinese intact --- what do I do?

LT

Keleth
11-11-2010, 01:33 AM
htmlentities defaults to ISO-8859-1, which is Western Latin.

http://php.net/manual/en/function.htmlentities.php

Read up on charset options, and apply that. If you're expecting multiple languages, you might be out of luck.

low tech
11-11-2010, 01:42 AM
Hi Keleth

thanks

yeh I have set up for chinese in page and DB --

chinese works in the page and database but if that filter function is used it scrambles it in databse which of course is echoed back to page scrambled

So what in that functinn can do that to chinese??

or do you mean I should add something to that function??

sorry not i'm really clear

LT

Keleth
reading the page you provided, its the BIG 5 I need to accept

which I do in my meta tag --- is that what you mean?

Keleth
11-11-2010, 02:06 AM
Right, if you read the documentation, it states you set that as an argument for it to filter with that charset.

low tech
11-11-2010, 02:30 AM
Hi Keleth

and thanks again


set that as an argument for it to filter with that charset

Ok i'm with ya ----- but how to do that?? I really have no clue about what to put where:-(


function filter($data) {
$data = trim(htmlentities(strip_tags($data)));

if (get_magic_quotes_gpc())
$data = stripslashes($data);

$data = mysql_real_escape_string($data);

return $data;
}

LT

is this line wiping out the chinese? Is this the line I need to change?


$data = trim(htmlentities(strip_tags($data)));

Keleth
11-11-2010, 02:34 AM
Unless you're absolutely not understanding this, I am not a fan of simply giving out code... read example 2 of the documentation, it shows you exactly what you need, just as using utf-8 instead of big5

low tech
11-11-2010, 02:41 AM
Hi Keleth

sorry I am reading --- and reading -- and reading hahahhaa

and I do want to do it --- seriously

i'm not a coder --- sorry if I seem to be asking too much --- I don't expect you to give anything you are not willing offer

no offense intened

the help is really appreciated tho

LT
I am confused at what to do exactly.

peace:-)

ps
in doc page, I was at Tom Walter lookin at this line ---- hahahhaa does that show you i'm lost hhahaa


$str = htmlentities(iconv('UTF-8', 'UTF-8//IGNORE', $str, ENT_QUOTES, 'UTF-8');

low tech
11-11-2010, 03:29 AM
Hi

I have tried this but finally I had to comment out the line and chinese is ok

so I guess the question is what does that first line actually do and do I need it to strip other unwanted stuff?

My attempt (the second line didn't work --- I get error on page -- on a line way before)



function filter($data) {
// $data = trim(htmlentities(strip_tags($data))); // orignal line chaged to line below

// $data = htmlentities(iconv('UTF-8', 'UTF-8//IGNORE', $data, ENT_QUOTES, 'UTF-8');
// didn't work --- when taken out --- chinese ok

if (get_magic_quotes_gpc())
$data = stripslashes($data);

$data = mysql_real_escape_string($data);

return $data;
}

Also tried this but doesn't work


$data = htmlentities(iconv($data, ENT_QUOTES, 'UTF-8');

it seems my only option is to remve or comment out this line


$data = trim(htmlentities(strip_tags($data)));

LT

ps I read abouy strip_tags

is it really needed when there is


if (get_magic_quotes_gpc())
$data = stripslashes($data);

$data = mysql_real_escape_string($data);

Keleth
11-11-2010, 05:44 AM
I understand, the non-programmer thing... this is what you should be doing:


$data = trim(htmlentities(strip_tags($data), ENT_COMPAT, 'BIG5'));

low tech
11-11-2010, 06:27 AM
Hi Keleth

Yeh thanks --- magic

That code allows my chinese and I guess still does what it's supposed to do ---- better than just removing the code:-)

Sorry if it seemed like I wasn't trying. I love trying -- just not that good hahahhaa

anyway

thanks again

LT



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum