Current location: Hot Scripts Forums » Programming Languages » PHP » I want to be able to check a variable for a word. . .


I want to be able to check a variable for a word. . .

Reply
  #1 (permalink)  
Old 03-09-05, 07:11 PM
Spreegem Spreegem is offline
Newbie Coder
 
Join Date: Jan 2004
Location: In front of my computer
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
I want to be able to check a variable for a word. . .

I am wanting to see if the variable $username contains any profane words in it, I am using strpos like this . . .

PHP Code:

if (strpos($username, ****) === true)

{
echo 
'That does not appear to be a valid username, please try again.';
include 
'index.html';
exit();

It keeps echoing no matter what I enter. What am I doing wrong? Thank You in advance.
Reply With Quote
  #2 (permalink)  
Old 03-09-05, 10:34 PM
wings wings is offline
Newbie Coder
 
Join Date: Jan 2005
Location: my computer
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
I think your problem is that you have to enter an 'else' statement, otherwise it will just show the only value it knows, for example:
PHP Code:

if (strpos($username, ****) === true
{
    echo 
"That does not appear to be a valid username, please try again."
    include 
'index.html'
}
else
{
    echo 
"enter w/e you want to tell them that they have a valid username here";

Reply With Quote
  #3 (permalink)  
Old 03-10-05, 03:52 AM
Sabu Sabu is offline
Junior Code Guru
 
Join Date: Sep 2004
Posts: 458
Thanks: 0
Thanked 0 Times in 0 Posts
I think your problem is that strpos doesn't return TRUE in any instance. It's either a number, or FALSE. So perhaps

PHP Code:

if (strpos($username, ****) !== false)

{
echo 
'That does not appear to be a valid username, please try again.';
include 
'index.html';
exit();

Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
what is the best method to find last word in variable ? GS300 PHP 6 09-15-04 09:13 PM
PHP variable sharad PHP 2 09-10-04 02:06 PM
Can ASP check registry janice_2k ASP 0 05-31-04 03:28 AM
Sending a variable to a page redirected to with header() ? Frank PHP 3 05-19-04 08:02 AM
Call a variable name dynamically Kenrette ASP 2 11-12-03 09:48 AM


All times are GMT -5. The time now is 05:35 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.