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 February 10th, 2005, 02:59 AM
nevillemehta nevillemehta is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: India
Posts: 64 nevillemehta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 44 m 17 sec
Reputation Power: 7
Remove extra backslashes...

Hey,

Here is a php file called 'testonlinetxt.php'.

PHP Code:
<html>
<
body>

<
form method="GET" action="testonlinetxt.php">
    <
p><textarea rows="18" name="data" cols="92"><?=$data?></textarea></p>
    <input type="submit" value="SAVE" name="submit">
</form>

</body>
</html> 


Now enter http="www.sdf.com" and click on save. The page is reloaded and the text in the textarea is http=\"www.sdf.com\". Why am i getting those extra slashes? Can someone tell me how i could get rid of them?

Thanks
Neville

Reply With Quote
  #2  
Old February 10th, 2005, 04:59 AM
mattp23 mattp23 is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: UK
Posts: 82 mattp23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 6
You probalby want stripslashes

You probably have magic quotes turned on, if you were inserting into a database some characters like " and ' will mess it up, adding a slash to these characters (" becomes \" and ' becomes \') makes it safe for the db to store. You can use addslashes to do this.

Depending on your setup php will automatically call addslashes, it sounds like thats what its doing here.

I cant explain this very well, anyone else care to step in...
__________________
http://www.phptutorials.cjb.net. go on, give it a click!

Reply With Quote
  #3  
Old February 11th, 2005, 02:09 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
magic_quotes_gpc is pretty annoying isn't it?

Nevill,

You are having a very common problem. There are two ways to go about this, but one way is better.

First, I assume you have register_globals Off

If you are unsure, please check : http://forums.devarticles.com/t4391/s.html

Your stock php.ini configuration is going to have :
magic_quotes_gpc = On

In this case, each time you post data to a page, where there is a ' or a " you will get a slash (\) prepended to it automatically.

This is PHP trying to "Help You Out". Realistically, it is pretty annoying.

So, you can band-aid the problem in code by doing this:
PHP Code:
<textarea rows="18" name="data" cols="92"><?= stripslashes($data); ?></textarea> 


or, to eliminate the problem completely, you can just do the following:

In php.ini:
magic_quotes_gpc = Off

or In .htaccess
php_value magic_quotes_gpc off

Now, keep in mind, if you turn off magic_quotes_gpc and you actually need to escape quotes in your data such as inserting into a database, embedding strings inside of javascript, etc, you will have to use the function addslashes.

This is ok... it is not as annoying as having to stripslashes everything. My suggestion is to turn it off in php.ini or .htaccess.
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Remove extra backslashes...


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT