Jump to content

Check if a string has different characters


TEENFRONT

Recommended Posts

Hey

 

I have a chat system and i need to check if a string contains only 1 character for example

 

$var = ".......................";

 

i need to block out that, so id need to check if $var only contained a full stop, or anything like

 

$var = "aaaaaaaaaaaaaaaaaaaa";

 

etc.

 

Im trying to stop people from flooding the chat with fullstops and one letters etc. i can stop them flooding when $var is empty by checking if $var = "";  but i dont know how to check if the var only contains one set of characters repeated like the above examples, any help?

Hey

 

I have a chat system and i need to check if a string contains only 1 character for example

 

$var = ".......................";

 

i need to block out that, so id need to check if $var only contained a full stop, or anything like

 

$var = "aaaaaaaaaaaaaaaaaaaa";

 

etc.

 

Im trying to stop people from flooding the chat with fullstops and one letters etc. i can stop them flooding when $var is empty by checking if $var = "";  but i dont know how to check if the var only contains one set of characters repeated like the above examples, any help?

 

<?php
$str = $_POST['form'];
$num_char = strlen($str);
$num_char = $num_char - 1;
for($counter =0; $counter <= $num_char; $counter++)
{
if($str[$counter] == $first || $str[$counter] == $second)
{ $error = 1; break;}
$first = $str[$counter -2 ];
$second =$str[$counter -1 ];
}
if($error)
{
echo 'Error, you are entering repeat characters.';
}
?>

 

Hope this helps,

Jack.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.