|
-
May 11th, 2002, 05:41 AM
#1
Thread Starter
PowerPoster
AAARRGGHHHH!!!!! Why is this so difficult????
Everyone told me PHP is easy. Now it won't accept a string with an apostrophe in it. What do I do about that?
UserName = Bob
Email = [email protected]
Comments = These are Bob's comments
It won't accept that. Why not? What do I do about it????
-
May 11th, 2002, 10:06 AM
#2
PowerPoster
' is a string character as in most languages, therefore you have to "escape" it with the escape char \
$string = 'these are bob\'s comments';
You can get PHP to do it automatically turning the magic_quotes_gpc (for POST GET COOKIE data) and magic_quotes_runtime (for mysql data) directives on in your php.ini, or to do it in the script use the addslahes() function. Conversely, you can use stripslashes() function to remove them again if you want to display the output on the screen.
Last edited by chrisjk; May 11th, 2002 at 10:09 AM.
-
May 13th, 2002, 11:09 AM
#3
Stuck in the 80s
When you have this:
$x = 'these are bob's comments';
the string ends at the next appostrophe, after bob. So with "s comments" it's searching for functions and stuff like that.
If you know VB, it'd be like doing this:
strString = "What's up," billy?
You know that "billy?" would cause a syntax error.
In order to fix this, you'd either have to escape it, like Chris showed, or if you know there's not going to be double quotes in the string, do this:
"these are bob's comments" or
'these are bob\'s comments"
I hope you're starting to understand all this. PHP is a really awesome language once you get a handle on it. Best of luck.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|