PHP/MySQL Script add-on

Discussion in 'Programming' started by ballestplaya, Mar 14, 2010.

  1. #1
    Hey guys I need help with implementing a function... The website is: http://www.undergroundcentral.us / I need the most recent searches to be filtered... I don't want porn and other words to show up on there (some people search the most bizarre thing, not everybody wants see that...). I believe that this is the function:

    
    function showhistory ()
      {
        if (!($sql = mysql_query ('SELECT * FROM `general` WHERE `Name` = \'Search_Divider\'')))
        {
          exit ('<b>SQL ERROR:</b> 102, Cannot write history.');
          ;
        }
    
        while ($row = mysql_fetch_array ($sql))
        {
          $divider = '' . $row['Value'];
        }
    
        if (!($sql = mysql_query ('SELECT * FROM `general` WHERE `Name` = \'History_Limit\'')))
        {
          exit ('<b>SQL ERROR:</b> 102, Cannot write history.');
          ;
        }
    
        while ($row = mysql_fetch_array ($sql))
        {
          $history_limit = '' . $row['Value'];
        }
    
        if (!($sql = mysql_query ('' . 'SELECT * FROM `history` ORDER BY `ID` DESC LIMIT ' . $history_limit)))
        {
          exit ('<b>SQL ERROR:</b> 102, Cannot write history.');
          ;
        }
    
        $return_amount = mysql_num_rows ($sql);
        while ($row = mysql_fetch_array ($sql))
        {
          $search = '' . $row['Query'];
          echo '<a href="file_' . urlencode ($search) . '.html">' . urldecode ($search) . '</a>';
          if ($i + 1 < $return_amount)
          {
            echo '' . ' ' . $divider . ' ';
          }
    
          ++$i;
        }
    
    
    PHP:
    How can I make it check a .txt file where I would store the banned words and filter them out before it's displayed on the main page?

    Thanks
     
    ballestplaya, Mar 14, 2010 IP
  2. YoGem

    YoGem Active Member

    Messages:
    676
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    90
    #2
    Are you planning a bad word filter? I mean, a script that wont show most recent articles if they show offensive words?

    You can do something, I suppose you have a main php file containing the configuration, right?

    Create an array:

    
    $bad_words = array ('badword1','badword2','badword3');
    
    PHP:
    Then you can create a simple function like this one:

    
    
    function isbad($text) 
    {
    
    foreach ($bad_words as $bw) { $a = strpos(strtolower($text), strtolower($bw));  
                                                   if ($a <> 0) { $ba_wo.=+1; }
                                                }
    
                                                   if ($ba_wo == 0) { return false; }
                                                   else { return true; }
    }
    
    PHP:
    if the function return false you can publish the link otherwise it's better to pass to the next one.

    I think it should work...

    (One day my english will sound like english >_< )
     
    YoGem, Mar 15, 2010 IP