PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 18th, 2004, 02:12 PM
whartmaniv whartmaniv is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 whartmaniv User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Please help me allow apostrophes(') in form fields

Hello. I am trying to allow users to enter apostrophes into html form fields, but I am encountering a lot of problems. It seems that automatically the $_POST variable inserts a \' for every apostrophe. This would be find except that now I have a php variable with a \' in it. Here is the problem:


$form_input = "John's Party"

If I use echo "$form_input";
=> John\'s Party

If I use echo '$form_input';
=> $form_input

If I use strtr("\","","$form_input) or str_replace("/","",$form_input)
=> I get a parse error because it recognizes \" as one character.

How can I get rid of the \. I use "" for all my echo statements so I don't ever need it anyway.

THANK YOU FOR YOUR HELP. THIS IS REALLY STUMPING ME (Yes, I'm pretty new to PHP).

Reply With Quote
  #2  
Old July 18th, 2004, 02:27 PM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 11
Theres a php function called strip_slashes (might be stripSlashes) that will remove them for you.

-KM-

Reply With Quote
  #3  
Old January 4th, 2005, 06:03 PM
bud1960 bud1960 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 1 bud1960 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
When you enclose a variable name in apostrophes, PHP thinks you want to display the field.

HTH,
Bud

Reply With Quote
  #4  
Old January 5th, 2005, 07:47 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 14
If I use strtr("\","","$form_input) or str_replace("/","",$form_input)

You have to escape the slash... str_replace("\\","",$form_input) would have worked...

A slash itself is usually used to escape special characters in a string (such as single quote, double quotes, and a backslash)...
For example, if you wanted to put quotes in your string you would use \" within the string... when printed to the screen it usually displays without the backslash...

Example:
$str="So then he said \"Spam sucks\"";
$coolW="\\/\\/"; (would display \/\/)

$str="So then he said "Spam sucks""; would throw an error

However, in your case stripslashes() is a much better solution =)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Please help me allow apostrophes(') in form fields


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap