Hi,
Im building a project that allows someone to add, edit, and delete a certain entry. Now this entry has all different types of characters, so ', /, \, etc. Im having problems with this. When I add an entry, i use the addslashes function, and when I display/edit them I use the strip slashes function, allthough this doesnt allways work. For example, when I make a new entry that looks like this: c:\oij'\/\
it comes out looking like this: c:oij'/ and then when I edit it again, it looks like this: c:\oij
Can someone please help me with these types of characters
Help with php forms
Moderator: General Moderators
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
Code: Select all
$noslashes = str_replace("\", "", $stringtoreplace);when magic_quotes is enabled, slashes are added automaticly. You don't want that so
- check for the setting of magic_quotes_gpc
- if enabled use stripslashes to get rid of the added slashes
- else do nothing
- then if you output the data to a database use mysql_real_escape_string() (in case of an mysql database) to escape 'dangerous/unwanted' characters
Now all data is in the db as wanted, without any redundant slashes.
- check for the setting of magic_quotes_gpc
- if enabled use stripslashes to get rid of the added slashes
- else do nothing
- then if you output the data to a database use mysql_real_escape_string() (in case of an mysql database) to escape 'dangerous/unwanted' characters
Now all data is in the db as wanted, without any redundant slashes.
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
In theory, this should be true:
And when tested on my system, it does just that.
It must be something with your code, whether it's the order you put the functions, or maybe that you forgot to use add/stripslashes after/before editing?
Code: Select all
<?php
$string = "C:\directory\file.jpg";
$safeString = addslashes($string);
$printableString = stripslashes($safeString);
echo "safeString = " . $safeString . "<br/>";
// safeString = C:\\directory\\file.jpg
echo "printableString = " . $printableString . "<br/>";
//printableString = C:\directory\file.jpg
?>It must be something with your code, whether it's the order you put the functions, or maybe that you forgot to use add/stripslashes after/before editing?