Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.