Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8250043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:45:20+00:00 2026-06-07T23:45:20+00:00

I am trying to integrate php bad words filter The input is taken through

  • 0

I am trying to integrate php bad words filter
The input is taken through $_REQUEST[‘qtitle’] and $_REQUEST[‘question’]
But I am failed to do so

$USERID = intval($_SESSION['USERID']);

if ($USERID > 0)
{
$sess_ver = intval($_SESSION[VERIFIED]);
$verify_asker = intval($config['verify_asker']);
if($verify_asker == "1" && $sess_ver == "0")
{
    $error = $lang['225'];
    $theme = "error.tpl";
}
else
{
    $theme = "ask.tpl";
    STemplate::assign('qtitle',htmlentities(strip_tags($_REQUEST['qtitle']), ENT_COMPAT, "UTF-8"));
    STemplate::assign('question',htmlentities(strip_tags($_REQUEST['question']), ENT_COMPAT, "UTF-8"));
    if($_REQUEST['subform'] != "")
    {
        $qtitle = htmlentities(strip_tags($_REQUEST['qtitle']), ENT_COMPAT, "UTF-8");
        $question = htmlentities(strip_tags($_REQUEST['question']), ENT_COMPAT, "UTF-8");
        $category = intval($_REQUEST['category']);


        if($qtitle == "")
        {
            $error = $lang['3'];
        }
        elseif($category <= "0")
        {
            $error = $lang['4'];
        }
        else
        {
            if($config['approve_stories'] == "1")
            {
                $addtosql = ", active='0'";
            }
            $query="INSERT INTO posts SET USERID='".mysql_real_escape_string($USERID)."', title='".mysql_real_escape_string($qtitle)."',question='".mysql_real_escape_string($question)."', tags='".mysql_real_escape_string($qtitle)."', category='".mysql_real_escape_string($category)."', time_added='".time()."', date_added='".date("Y-m-d")."' $addtosql";
            $result=$conn->execute($query);
            $userid = mysql_insert_id();
            $message = $lang['5'];
        }
    }
}
}   

else
{
$question = htmlentities(strip_tags($_REQUEST['qtitle']), ENT_COMPAT, "UTF-8");
$redirect = base64_encode($thebaseurl."/ask?qtitle=".$question);
header("Location:$config[baseurl]/login?redirect=$redirect");exit;
}

I am trying the following code but this code replaces every word (which is not included in the array)

FUNCTION BadWordFilter(&$text, $replace){

$bads = ARRAY (
  ARRAY("butt","b***"),
  ARRAY("poop","p***"),
  ARRAY("crap","c***")
);

  IF($replace==1) {                                        //we are replacing
  $remember = $text;

  FOR($i=0;$i<sizeof($bads);$i++) {               //go through each bad word
       $text = EREGI_REPLACE($bads[$i][0],$bads[$i][1],$text); //replace it
  }

  IF($remember!=$text) RETURN 1;                     //if there are any changes, return 1

 } ELSE {                                                  //we are just checking

  FOR($i=0;$i<sizeof($bads);$i++) {               //go through each bad word
       IF(EREGI($bads[$i][0],$text)) RETURN 1; //if we find any, return 1
  }     
 }
}
$qtitle = BadWordFilter($wordsToFilter,0); 
$qtitle = BadWordFilter($wordsToFilter,1); 

What I am missing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:45:23+00:00Added an answer on June 7, 2026 at 11:45 pm

    I agree with @Gordon that this is reinventing the wheel, but if you really want to do it, here’s a better start:

    function badWordFilter(&$text, $replace)
    {
        $patterns = array(
            '/butt/i',
            '/poop/i',
            '/crap/i'
        );
    
        $replaces = array(
            'b***',
            'p***',
            'c***'
        );
    
        $count = 0;
        if($replace){
            $text = preg_replace($patterns, $replaces, $text, -1, $count);
        } else {
            foreach($patterns as $pattern){
                $count = preg_match($pattern, $text);
                if($count > 0){
                    break;
                }
            }
        }
    
        return $count;
    }
    

    There are lots of inherent issues, though. For instance, run the filter on the text How do you like my buttons? … You’ll end up with How do you like my b***ons?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to integrate paypal in a php website but I'm not sure how
I am trying to integrate a simple login for my site with php. i
I'm trying to integrate FNV hashing algorithm on a PHP-based project as part of
So I am trying to integrate fedex for web services in php. The form
I have a php application , and I'm trying to integrate with paypal payment
I'm trying to integrate passport into my nodejs server using connect, but can't seem
I am trying to integrate two PHP scripts (app1, app2) and I am trying
I'm trying to integrate the PHP script AutoEmbed, however I noticed that the regular
So I'm trying to integrate the PHP facebook SDK/API with codeigniter, because I love
I am trying to integrate isotope but Iam having problems getting it to work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.