Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    891
    Thanks
    174
    Thanked 102 Times in 102 Posts

    what to use instead of filter?

    Hello all

    I have this probelm

    I input Chinese text to send to DB

    but this php code is used

    PHP Code:
    $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
    Last edited by low tech; 11-11-2010 at 06:32 AM.

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    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?

  • Users who have thanked kbluhm for this post:

    low tech (11-11-2010)

  • #3
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    891
    Thanks
    174
    Thanked 102 Times in 102 Posts
    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

    PHP Code:
    ////////// 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

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    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?

  • #5
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    It'd be a variable function name:
    PHP Code:
    $fetch 'mysql_fetch_assoc';

    $row   $fetch$result ); 
    So based on the possible values of $filter, there may be multiple pieces of code to debug.

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Quote Originally Posted by kbluhm View Post
    It'd be a variable function name:
    PHP Code:
    $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...

  • #7
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    891
    Thanks
    174
    Thanked 102 Times in 102 Posts
    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


    PHP Code:
    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
    Last edited by low tech; 11-11-2010 at 01:32 AM.

  • #8
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    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.

  • #9
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    891
    Thanks
    174
    Thanked 102 Times in 102 Posts
    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?
    Last edited by low tech; 11-11-2010 at 01:46 AM.

  • #10
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Right, if you read the documentation, it states you set that as an argument for it to filter with that charset.

  • #11
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    891
    Thanks
    174
    Thanked 102 Times in 102 Posts
    Hi Keleth

    and thanks again

    PHP Code:
    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:-(

    PHP Code:
    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?

    PHP Code:
    $data trim(htmlentities(strip_tags($data))); 
    Last edited by low tech; 11-11-2010 at 02:36 AM.

  • #12
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    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

  • #13
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    891
    Thanks
    174
    Thanked 102 Times in 102 Posts
    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

    PHP Code:
    $str htmlentities(iconv('UTF-8''UTF-8//IGNORE'$strENT_QUOTES'UTF-8'); 
    Last edited by low tech; 11-11-2010 at 02:44 AM.

  • #14
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    891
    Thanks
    174
    Thanked 102 Times in 102 Posts
    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)


    PHP Code:
    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

    PHP Code:
    $data htmlentities(iconv($dataENT_QUOTES'UTF-8'); 
    it seems my only option is to remve or comment out this line

    PHP Code:
    $data trim(htmlentities(strip_tags($data))); 
    LT

    ps I read abouy strip_tags

    is it really needed when there is

    PHP Code:
        if (get_magic_quotes_gpc())
        
    $data stripslashes($data);
        
        
    $data mysql_real_escape_string($data); 
    Last edited by low tech; 11-11-2010 at 04:14 AM.

  • #15
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    I understand, the non-programmer thing... this is what you should be doing:

    PHP Code:
    $data trim(htmlentities(strip_tags($data), ENT_COMPAT'BIG5')); 

  • Users who have thanked Keleth for this post:

    low tech (11-11-2010)


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •