Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-21-2002, 05:35 PM   PM User | #1
Hatch
New Coder

 
Join Date: Jun 2002
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Hatch is an unknown quantity at this point
checking string for '

I'm using php.
I have a text box in a form and I want to check if they have typed in a ' charactor in that field. How do i do that in php.
Thanks
Hatch is offline   Reply With Quote
Old 06-21-2002, 06:51 PM   PM User | #2
SYP}{ER
Regular Coder

 
Join Date: Jun 2002
Location: Ontario, Canada
Posts: 183
Thanks: 0
Thanked 0 Times in 0 Posts
SYP}{ER is an unknown quantity at this point
PHP Code:
if (strstr ($string_to_search"'")!=false){
  
//Yup, they typed it.
}else{
  
//Nope, they didn't type it.

Note that if you're trying to comment them out, you can use
PHP Code:
addslashes() 
or to remove the slashes, you can use
PHP Code:
stripslashes() 
__________________
Offtone.com - In the works...
SYP}{ER is offline   Reply With Quote
Old 06-22-2002, 01:24 PM   PM User | #3
Jeewhizz
Regular Coder


 
Join Date: May 2002
Location: London, England
Posts: 369
Thanks: 0
Thanked 0 Times in 0 Posts
Jeewhizz is an unknown quantity at this point
aaron was nearly right... tho one error.. use this code

PHP Code:
if (strstr ($string_to_search"'")!==false){
  
//Yup, they typed it.
}else{
  
//Nope, they didn't type it.

Jee

P.s. junior members eh
__________________
Jeewhizz - MySQL Moderator
http://www.sitehq.co.uk
PHP and MySQL Hosting
Jeewhizz is offline   Reply With Quote
Old 06-25-2002, 11:03 PM   PM User | #4
SYP}{ER
Regular Coder

 
Join Date: Jun 2002
Location: Ontario, Canada
Posts: 183
Thanks: 0
Thanked 0 Times in 0 Posts
SYP}{ER is an unknown quantity at this point
Hey, what was my mistake? the !== instead of !=?

Well check THIS out, mista:

http://www.aaron-wright.com/grr.php



If I'm still wrong, please clarify. lol
__________________
Offtone.com - In the works...
SYP}{ER is offline   Reply With Quote
Old 06-28-2002, 10:33 PM   PM User | #5
ReadMe.txt
Regular Coder

 
Join Date: Jun 2002
Location: Sheffield, UK
Posts: 552
Thanks: 0
Thanked 0 Times in 0 Posts
ReadMe.txt is an unknown quantity at this point
i'd have to say that aarons right !== is not correct AFAIK, unless PHP has been changed
__________________
"To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

(Me Me Me Me Me Me Me Me Me)
ReadMe.txt is offline   Reply With Quote
Old 06-28-2002, 10:52 PM   PM User | #6
SYP}{ER
Regular Coder

 
Join Date: Jun 2002
Location: Ontario, Canada
Posts: 183
Thanks: 0
Thanked 0 Times in 0 Posts
SYP}{ER is an unknown quantity at this point
Jee may be right actually, but only if you're using the latest version of PHP I heard there were some changes being made and that we'll all have to get used to them, but then again I could be terribly misinformed and maybe there isn't even a new version of PHP

I need to sit down.
__________________
Offtone.com - In the works...
SYP}{ER is offline   Reply With Quote
Old 06-28-2002, 11:14 PM   PM User | #7
Thejavaman1
New Coder

 
Join Date: Jun 2002
Location: Stuck in the inner reaches of my mind
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Thejavaman1 is an unknown quantity at this point
or just
PHP Code:
if(strstr($string_to_search"'")){

  
//Yup, they typed it.

}else{

  
//Nope, they didn't type it.


because not false is the same as true...
Thejavaman1 is offline   Reply With Quote
Old 06-30-2002, 03:48 PM   PM User | #8
mordred
Senior Coder


 
Join Date: Jun 2002
Location: frankfurt, german banana republic
Posts: 1,848
Thanks: 0
Thanked 0 Times in 0 Posts
mordred is an unknown quantity at this point
...but being exact, the return value of strstr() isn't a boolean true either - it's only casted to true in the if-statement.

Apparently Jeewhizz confused strstr() with strpos(), because with strpos() you have to be wary of a returned 0 which gets casted to false, that's why you should use !== instead of !=.

http://www.php.net/manual/en/function.strpos.php
mordred is offline   Reply With Quote
Old 06-30-2002, 10:30 PM   PM User | #9
Phip
Registered User

 
Join Date: Jun 2002
Location: Arizona
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Phip is an unknown quantity at this point
*reads post and laughs to self*
Phip is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:34 PM.


Advertisement
Log in to turn off these ads.