very simple question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

very simple question

Post by hob_goblin »

on my tagboard alot of people think its funny to post blank messages..

i figured out how to prevent them from making blank messages, but i can't figure out how to stop them from posting messages with only " " spaces..

i want to make it so if the name is less than three characters it wont post, same with the message

what are the wild cards to do this?

if($var <= "whatgoeshere"){
Bart
Forum Newbie
Posts: 9
Joined: Sat May 04, 2002 12:12 pm
Location: Ontario Canada

Post by Bart »

The strlen() function can find out the Strings Length, so something like so should work:

Code: Select all

if (strlen($var) < 3) &#123; // Post error message or something &#125;
pozytron
Forum Newbie
Posts: 12
Joined: Fri May 03, 2002 7:14 pm
Location: Denver

Post by pozytron »

You might want to make it check for spaces as well as for string length. To do that, here's an example:

Code: Select all

if (strlen(str_replace(" ","",$var)) < 3) &#123;
// Post error message or something
&#125;
This code simply tests the length of the string when there aren't any spaces. You could use trim() or chop() or something of the like, but then someone could just type "x x" and easily bypass the validation. The above method actually works pretty well.
Cheers
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

thanks alot guys..it worked well :D
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

what about this easy solution

Post by dethron »

Hi Guys,

Why we don't use

Code: Select all

if($var)&#123; 
           echo "Text Here";
           &#125; 
     else&#123; 
           echo "Fill all fields";
           &#125;
If $var is posted, then execute queries or display outputs, else just type an error messages or redirect another file :)

I think it will work too, am i right?
dusty
Forum Contributor
Posts: 122
Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA

Post by dusty »

nope! spaces would make $var true, but it'd still be a blank message.
Post Reply