Block contained text in a field?

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
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Block contained text in a field?

Post by Citizen »

Is there a way to do this?

Code: Select all

if ($variable contains "textstring"){
echo "invalid text";
}
So that if the $variable was hellotextstringworld, it wouldnt work.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post by Citizen »

Thanks!
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post by Citizen »

I got it to work for one of my fields, but this one doesnt seem to be working:

Code: Select all

$findme2 = 'visitshark';
$pos2 = strpos($website, $findme2);
if ($pos2 === true) {
echo "Links containing VisitShark are not permitted for security reasons. Please enter a valid website address.";
}
Any ideas why this one isnt working? Do I have to change the === if i'm checking for "true" instead of "false"?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Citizen wrote:I got it to work for one of my fields, but this one doesnt seem to be working:

Code: Select all

$findme2 = 'visitshark';
$pos2 = strpos($website, $findme2);
if ($pos2 === true) {
echo "Links containing VisitShark are not permitted for security reasons. Please enter a valid website address.";
}
Any ideas why this one isnt working? Do I have to change the === if i'm checking for "true" instead of "false"?
This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "". Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.
Check for False not true
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post by Citizen »

Thanks, I ended up doing a (!($pos === false)) :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ahem:

$pos !== false
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post by Citizen »

feyd wrote:ahem:

$pos !== false
Doh! Thanks feyd!
Post Reply