-Oops, sorry!- I posted in the wrong area! Can someone move this thread please?
Ok, I got a array going with the words I want. So if someone posted any of those words I want the script to show a message. So this is what I have so far:
[PHP]$message = $_POST['message'];
$filter = array("word", "word2", "word3");
if($message == badword)
{
//Show error message
}else{
//post message
}[/PHP]
I know the if line wont work, but I just wanted to throw it out their as a example of what I want to do.
Any suggestions?
7 2430 Atli 5,058
Expert 4TB
I'm moving this thread to the PHP Forums.
Please refrain from posting in the Articles section! Moderator Atli 5,058
Expert 4TB
You could do something like this: -
$message = $_POST['message'];
-
$searchWord = array("word1", "word2", "...");
-
-
foreach($searchWord as $word)
-
{
-
if(strpos($message, $word) != false) {
-
echo "Invalid word detected!";
-
exit;
-
}
-
}
-
echo "Its all good!";
-
Heya, Ajm. -
$badwords = array( ... );
-
$post = implode(' ', array_diff(explode(' ', $post), $badwords));
-
Heya Pbmods
Would you please mind of you can afford to elaborate a bit on this?
Code:( php )
1. $badwords = array( ... );
2. $post = implode(' ', array_diff(explode(' ', $post), $badwords));
Does this just filter bad words silently or how this would fit in the code above?
Thanks a lot
This is the answer i think...
[PHP]
$string=$_POST['string'];
$bad=array();
foreach($bad as $i){
$string=str_replace($i," CENSORED ",$string);
}
[/PHP]
Have a nice day,
Luke14free
Heya, Jankie.
Would you please mind of you can afford to elaborate a bit on this? - $badwords = array( ... );
-
$post = implode(' ', array_diff(explode(' ', $post), $badwords));
Does this just filter bad words silently or how this would fit in the code above
This code does filter out the bad words silently. It explode()s the post, using space characters (i.e., creates an array containing every word in the post). Then it removes all words that match any of the *keys* in $badwords (you'll need to make the bad words keys), and then implode()s the array back into a string, reinserting the spaces.
The one problem with this algorithm is that it doesn't take punctuation into account.
The foreach method would be your best bet, but don't use strpos(). strpos() can return 0, which is equivalent to false. Use stristr(), which will either return the string (if you which to str_replace it) or FALSE, and is case insensitive as well.
pbmods method could be done much faster by using only str_replace() instead of implode and explode.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Leo P. |
last post by:
I am trying to write a spelling checker. Specifically the part that
suggests words. From what I've read online, it seems like the
preferred way to do this, is to find the double metaphone...
|
by: Frances Del Rio |
last post by:
if (parent.frames.main.location == 'mediaselect.html') {
I have a very simple frameset, name of frame where I'm checking is
'main'... why is this not working? I mean this is correct syntax,...
|
by: Deb via AccessMonster.com |
last post by:
I have a comment field on my form and want to be able to find similar themes within comments that occur the most within a specific complaint code, i.e.: complaint code = 1 and the common theme from...
|
by: Clint Olsen |
last post by:
Hello:
I posted a thread on comp.programming awhile back asking about an algorithm
I implemented on square root. The idea was to use the square root of a
prime number as a convenient way to get...
|
by: Luke Matuszewski |
last post by:
Hi !
I have faced the problem of checking that the user has entered the
unicode letter (not only ASCII set of letters...). It seems that
ECMAScript 3rd regular expressions do not include posix...
|
by: Simon |
last post by:
Well, the title's pretty descriptive; how would I be able to take a
line of input like this:
getline(cin,mostrecentline);
And split into an (flexible) array of strings. For example: "do this...
|
by: lawrence k |
last post by:
I've made it habit to check all returns in my code, and usually, on
most projects, I'll have an error function that reports error messages
to some central location. I recently worked on a project...
|
by: bigbagy |
last post by:
Notes
The programs will be compiled and tested on the machine which runs the
Linux operating system. V3.4 of the GNU C/C++ compiler (gcc ,g++) must be used.
A significant amount coding is...
|
by: Brent |
last post by:
I have a list of company names (say, IBM, Corning, General Motors, and
another 5,000 of them).
If I take a body of text, a news article, for instance, and I want to
see which company names...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |