i have this script it wont display the page if i have over like 30 things in an array. wtf but it will display if theres only like 20. does anyone know what i can use instead of array() because i have like 100 things i need to use in an array

heres the code im working on to make sure that people cant register on my site with prohibited words in their usernames they pick:

$lowercaseusername = $username;
$lowercaseusername = preg_replace("/[^a-z]/i", "", $lowercaseusername);
$lowercaseusername = strtolower($lowercaseusername);
$banned = ("this", "times", "like", "100");
 
 $trimthex = trim($lowercaseusername, "x");
 var_dump($trimthex);

function stristr_array( $trimthex, $banned ) {
	foreach ($banned as $singleword ) {
		if (strstr($trimthex, $singleword) != FALSE){
		exit("cannot have $singleword in your usernname!");}}
}
$lowercaseusername = preg_replace("/[^a-z]/i", "", $lowercaseusername);

You do realize that'll remove any letter, whether it's uppercase or lowercase from the string, right? So ShawnCplus123 becomes 123 . Then your strtolower does nothing because there is nothing in the string except non-alpha characters. Remove the i off the end of the regular expression, that's telling it to be case insensitive so /[^a-z]/i is the same as /[^A-Za-z]/

no the carot negates it. itll remove everything that isnt an uppercase or lowercase letter hence the /i

no the carot negates it. itll remove everything that isnt an uppercase or lowercase letter hence the /i

You're right, it's been a long day :)
There's nothing really in that small block that limits how many items there will be in the array so it pretty much has to be elsewhere. As an aside, what is the trimthex for and where is the x coming from in the first place?

takes out the x;s so people cant get away with
ixhatexyourxsite no its the array amount my page wont display ill take out like half of the words ive got so far and it will work i added more than then it stopped working

Have you tried reading the words in from a file or DB? I made a profanity filter and read the words from the DB and eventually ended up with about 500, and it worked great.

If they're in a DB table, you could also run a single query such as:

str_sql = sprintf("select `id` from `profanity` where `word` like '%%%s%%'", 'username');

Replace username with the username provided, and if you get any results, you know the username is profane and should be banned

R

i have to just put it all in one pae because the include will not work.. so im doing that i got it to work all but the trimx i cannot think of how to get the x's out of the username

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.