ok am trying to add a simple word filter for my registration process I have stored all names i do not wish to be used in my db as a text and it can be edited via admin panel nicely but my problem is how can i scan the full reg section and then block reg if a name is in the list for example

username: Employee-frank this would be blocked but i like it to be flexable so that the word employee is not fully blocked only in the ways its found in filter db

so if i was to put username: fankemployee it would allow it can any one help??

cheers

Recommended Answers

All 10 Replies

The reality is you will need a long text list however, php does have some nice functions to make the list shorter. Say you want to match the word frank in all usernames (eg. "franky" or "dfrankzilla") then php has a function called substr_count(). If however you wish for a word to be matched by how it sounds then php has a function named soundex(). In those two pages you can check the links on the left hand side for more functions that may be suitable. So in simple you would loop through your list of words and check if the word occurs as part of the username or if it sounds similar to the username. That's the easiest way to filter it and shorten the list. :)

problem is its stored as a text in database

and its stores names like this

name1
name2
name3

no spaces or || so how would i be able to match any name in the database

table is following

`reg_filter` text NOT NULL,

i tried following

$bad_words = explode('', $core->reg_filter);
          foreach ($bad_words as $_POST['username'])
          {
             $core->msgs['bad'] = 'This account name is invalid because of reserved, or disallowed words.';
          }

but that blocks all names even onces not in list

sounds like poor database design. perhaps you need to rethink how you store the names in the first place. are those names
name1
name2
name3
in three different rows or is this one big text field that actually looks like
name1name2name3
?

one big line but i can add code to add \n for each line just i dont no how to read the information so when i view page it shows the names correctly in the memo box and when i try to register a name it will search each name in box and if found give error else allow them to make name

for example i since added \n

(capt)\\n(captain)\\n

how it looks but also how it looks in my box

as this screen shot shows

http://oi51.tinypic.com/iveqzl.jpg

how would i make it so there are perfectly lined one after other with out /n??

it appears as though you are using a framework. what framework is that? it also appears to be outputting html in that particular box, where <br /> would be more appropriate as opposed to /n. but I would not want to store all of that in the db.
I would imagine that typing in one line, then hitting return and typing in the next word may store properly in your db, but where is your code that is doing the 'search' on the 'restricted' key word list?

when person registers on front page it will check db to see if any tags or names are in filter field and then reject if there is and am using ajex/swift for my script

Member Avatar for diafol

Don't know if I got this right:

You could store names individually in DB as regex, e.g. (1) ffyc(ar)*, (2) \bffycar

ANyway, you seem to be using this:

grab data from DB and display as long text -> modify -> write back to DB

That's screwy - the read is easy, but a simple write back is almost impossible - unless you delete all records and then insert the new data.

Thought of just keeping a simple text file instead of records:

readfile -> into array -> check name against array item patterns.

Read/Writes should be easier (ok will be a little slower, but how many terms will there be anyway?)

i guess maybe better

Member Avatar for diafol

TBO Simon, I don't know. It just strikes me as the easiest option, perhaps not necessarily the best. Some expert here may have a really nifty query / bit of code that does all this for you, but it strikes me as 'dangerous' when you're trying to delimit your text with \\n. If you delete the first term, then edit the second item (etc), how will the DB know which records to delete and update?

TBO Simon, I don't know. It just strikes me as the easiest option, perhaps not necessarily the best. Some expert here may have a really nifty query / bit of code that does all this for you, but it strikes me as 'dangerous' when you're trying to delimit your text with \\n. If you delete the first term, then edit the second item (etc), how will the DB know which records to delete and update?

I would have to agree with you and may I ask the original poster, "Why not have a table of two columns with each row on the first column containing each word to filter and each row on the second column containing a number determining weather the word filters soundex or substr_match or both?" That would be the most logical thing to do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.