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 1000313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:29:31+00:00 2026-05-16T07:29:31+00:00

I writing a php function to check existence of bad whole words (keep in

  • 0

I writing a php function to check existence of bad whole words (keep in mind whole word not sub-strings) and also highlight whole words in given string.

function badwordChecherAndHighLighter($str,$replace){
// $replace=1  will  Highlight
// $replace=0  will  Check the existence of any badwords

$result = mysql_query("SELECT settings_badwords_en,settings_badwords_ar FROM settings_badwords WHERE settings_badwords_status=1") or die(mysql_error());

// i dont create an array, may create overhead, so i directly apply in preg_replace

if($replace==1){
while($row = mysql_fetch_row($result))
{
//$str=preg_replace('/'.$row[0].'/i', str_repeat("*",strlen($row[0])), $str);
$str=preg_replace('/\b('.$row[0].'\b)/i',"" .$row[0] . "" , $str);
$str=preg_replace('/\b('.$row[1].'\b)/i',"" .$row[1] . "" , $str);
}
return $str;
}else{

while($row = mysql_fetch_row($result))
{
 if(preg_match('/\b('.$row[0].'\b)/i',$str)) return 1;
 if(preg_match('/\b('.$row[1].'\b)/i',$str)) return 1;
}
return 0; 
}
}

// $row[1] conatin Arabic bad Words, and $row[0] contain English bad words.

This function gives correct results on Windows OS, WAMP5 1.7.3 for both Arabic and English.

But on Web Server It only works for English words, and not for Arabic.

So if Arabic text is given to this function , it is unable to check existence of any badword, and also unable to highlight arabic word.

I searched and try many options including \u but no error, no success.

So please help.

  • 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-05-16T07:29:32+00:00Added an answer on May 16, 2026 at 7:29 am

    The \b is not compatible the utf8 characters. Try this:

    preg_match('/(?<=^|[^\p{L}])' . preg_quote($utf8word,'/') . '(?=[^\p{L}]|$)/ui',$utf8string);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a construct in PHP where a parser determins which function to call
I'm writing a PHP application with testability in mind, so my classes always ask
I am writing a function that well keep the user in lightbox images while
I am writing a PHP mail function and some examples have @mail(…) and others
When I press Ctrl+P in NetBeans PHP while writing down function call parameters I
I've been writing PHP for about six years now and have got to a
I've been writing PHP web applications for some time, and have come across very
I am writing PHP code where I want to pass the session id myself
I'm writing a PHP script and the script outputs a simple text file log
I'm writing a php app to access a MySQL database, and on a tutorial,

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.