473,401 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Filtering out Bad Data

9
I have a site written in PHP that allows users to enter info into a form and upload an image. This information gets written to a MYSQL database. My question is how can I filter out dirty words and or pictures from being uploaded into my database ? Is there any simple way to handle this?
Feb 13 '08 #1
5 1138
harshmaul
490 Expert 256MB
Hi,
The images are going to have to be checked manually. (by yourself or a moderator), and the words can be filtered in a number of ways....

try this one

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $swears = array("swear","bad","naughty");
  3. $strMessage = str_replace($swears, "***", $strMessage);
  4. ?>
and then check this article...

http://uk.php.net/str_replace
Feb 13 '08 #2
Markus
6,050 Expert 4TB
If you want multiple replacements:
[php]
<?php
function filterContents($_str)
{
$_badWords = array("badword1", "badword2", "badword3", "badword4");
$_replace = array("****", "Removed", "OOPS!", "No can do!");

for($_i = 0; $_i < count($_badWords); ++$_i)
{
$_randKey = (rand()%count($_replace)); // random key
$_str = eregi_replace($_badWords[$_i], $_replace[$_randKey], $_str); //replace with a random replacement.
}
return $_str; //return.
}
$_content = "string here.. maybe some submitted comment.. badword1 badword2 badword3..";
echo filterContents($_content);

?>
[/php]
Feb 13 '08 #3
harshmaul
490 Expert 256MB
markus, Love the replacements!
Feb 13 '08 #4
Markus
6,050 Expert 4TB
markus, Love the replacements!
You should've seen what i had for the badwords before i realised i better take them out if i wanna remain on thescripts ;)
Feb 13 '08 #5
jtmphp
9
Perfect.
Thanks!
Feb 13 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: N.K. | last post by:
Hello, I'm trying to find a way to flexibly filter a column in a row of data read from a file. I will have data type of that column, the operation to be performed on it (like >, <, <= etc.) and the...
3
by: Alex Ayzin | last post by:
Hi, I have a problem that might be easy to solve(possibly, I've just overlooked an easy solution). Here we go: I have a dataset with 2 datatables in it. Now, I need to do the following: if...
3
by: Jason | last post by:
I am trying to filter records in a primary form based on records in related tables. The data in the related tables is being displayed in the primary form through subforms. To be more specific, I...
10
by: milk-jam | last post by:
I'm trying to set my datagridview so that the first row will be left blank and to use it as a filtering filed for the datagridview. Until now I was using 2 datagridview the upper one with a header...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
2
by: Jason Huang | last post by:
Hi, I use the ReadXML method in my C# Windows Form project. Here is some of my C# code: xmlDS.ReadXml(curDir + "\\Dept.xml") ; There're 20 rows and 5 columns in the Dept.xml. But now I just...
2
by: JUAN ERNESTO FLORES BELTRAN | last post by:
Hi you all, I am developping a python application which connects to a database (postresql) and displays the query results on a treeview. In adittion to displaying the info i do need to implement...
3
by: Shawn Ramirez | last post by:
As with most web applications speed is a huge deal to me in my applications. My customers don't really care if my app is a true 3 tier application or not, they just want it to be faster then it was...
3
by: Harry Haller | last post by:
Hello, I want to implement a generic list which will be used to display 7 columns in a GridView. One should be able to sort, filter and page each of the 7 columns. Ideally the filter should be...
0
by: Lyn | last post by:
I have a problem using the form .Filter and .FilterOn properties which causes Access to crash (as detailed in a separate post). The form operates in continuous mode, displaying matching records...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.