Please help with this small php code

Discussion in 'PHP' started by Divvy, Oct 7, 2010.

  1. #1
    hi fellows,

    can someone help me with a little thing?
    I have installed an wordpress plugin but I have a bug and the author didn't replied to my email...
    Look here: http://www.tugasapo.com/index.php?page_id=5593&layout=search

    The bug is:
    If you try to search with keyword "Smallville", dont appear any results.
    But If you try to search with keyword "smallville", It gives you results, because the search only works with lower cases.

    Can someone help me fixing this?

    I dont understand php language, but the few that I understand, I think that the problem is in this code:

    file data.php code:
    if(!empty($_POST['rsfl_keyword']))
                {
                    if(isset($_POST['rsfl_search']))
                    {
                        if(isset($_POST['rsfl_search'][0]) && isset($_POST['rsfl_search'][1]))
                        {    
                            if(strpos(strtolower($element->name),$_POST['rsfl_keyword']) === FALSE && strpos(strtolower($element->description),$_POST['rsfl_keyword']) === FALSE) continue;
                        }
                        elseif($_POST['rsfl_search'][0] == 'name')
                        {
                            if(strpos(strtolower($element->name),$_POST['rsfl_keyword']) === FALSE) continue;
                        }
                        elseif($_POST['rsfl_search'][0] == 'description')
                        {
                            if(strpos(strtolower($element->description),$_POST['rsfl_keyword']) === FALSE) continue;
                        }
                    }
                    else
                    {
                        if(strpos(strtolower($element->name),$_POST['rsfl_keyword']) === FALSE && strpos(strtolower($element->description),$_POST['rsfl_keyword']) === FALSE) continue;
                    }
                }
                
                $files[] = $element;
                
            }
    Code (markup):
    What I have to change? Please help... my php knowledge is very very poor...

    Thank you
     
    Divvy, Oct 7, 2010 IP
  2. YoGem

    YoGem Active Member

    Messages:
    676
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    90
    #2
    Take all the $_POST['rsfl_keyword'] and transform it to strtolower($_POST['rsfl_keyword'])
     
    YoGem, Oct 7, 2010 IP
  3. Divvy

    Divvy Well-Known Member

    Messages:
    785
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #3
    It works :D

    Thank you very much YoGem :)

    Btw, when I transformed the if(!empty($_POST['rsfl_keyword'])) to if(!empty(strtolower($_POST['rsfl_keyword']))) I got this error:

    Fatal error: Can't use function return value in write context in /home/sapo/public_html/wp-content/plugins/rsfiles/frontend/data.php on line 458

    But I turn back to if(!empty($_POST['rsfl_keyword'])) and the error disappeared and the search is working fine. I can leave that code like that right?

    Best regards and thank you again :)
     
    Last edited: Oct 8, 2010
    Divvy, Oct 8, 2010 IP
  4. YoGem

    YoGem Active Member

    Messages:
    676
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    90
    #4
    Well yes, I forgot to tell you not to touch the first line ;) yep it will work!

    Edit: Anyway strtolower is a function that transform every string in lowercase.
     
    Last edited: Oct 8, 2010
    YoGem, Oct 8, 2010 IP
  5. Divvy

    Divvy Well-Known Member

    Messages:
    785
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #5
    nice catch :)
    thank you again friend
     
    Divvy, Oct 8, 2010 IP