shazman Posted June 12, 2008 Share Posted June 12, 2008 I have a page that gets it's content from a text file. When the user modifies the page's content and uses a single quote anywhere, it puts a slash in front of it. Example: When you type "We're" it prints "We/'re" to the text file and displays that on the page. How can I make it not print the slashes. It also does this for double quotes. This makes things difficult when the user is adding a hyperlink. Link to comment https://forums.phpfreaks.com/topic/109817-solved-readingwriting-to-text-file-help/ Share on other sites More sharing options...
bluejay002 Posted June 12, 2008 Share Posted June 12, 2008 before writing text into a file, use addslashes().... then when retrieving, use stripslashes() before displaying. did it work? Link to comment https://forums.phpfreaks.com/topic/109817-solved-readingwriting-to-text-file-help/#findComment-563563 Share on other sites More sharing options...
DarkWater Posted June 12, 2008 Share Posted June 12, 2008 Use this: function unescape_data($string) { if (get_magic_quotes_gpc()) { return stripslashes($string); } else { return $string; } } You shouldn't need to escape data for writing it directly to a text file. Link to comment https://forums.phpfreaks.com/topic/109817-solved-readingwriting-to-text-file-help/#findComment-563566 Share on other sites More sharing options...
hansford Posted June 12, 2008 Share Posted June 12, 2008 bluejay002 is right. ` When you type "We're" it prints "We/'re" should be When you type "We're" it prints \"We\'re\" involking the addslashes() method Link to comment https://forums.phpfreaks.com/topic/109817-solved-readingwriting-to-text-file-help/#findComment-563572 Share on other sites More sharing options...
hitman6003 Posted June 12, 2008 Share Posted June 12, 2008 before writing text into a file, use addslashes().... then when retrieving, use stripslashes() before displaying. There's no reason to escape content in a text file. The whole purpose for magic_quotes_gpc was to prevent database injection attacks, because php developers, in the day of php 3, apparently couldn't be trusted to be smart enough to prevent it. It has nothing to do with text files, and should most certainly be disabled if possible. In php 6 magic_quotes_gpc won't even exist (along with register_globals), so this won't even be an issue. Darkwater's response is a viable method of removing the slashes if you can not disable the directive in php.ini. Link to comment https://forums.phpfreaks.com/topic/109817-solved-readingwriting-to-text-file-help/#findComment-563586 Share on other sites More sharing options...
DarkWater Posted June 12, 2008 Share Posted June 12, 2008 before writing text into a file, use addslashes().... then when retrieving, use stripslashes() before displaying. There's no reason to escape content in a text file. The whole purpose for magic_quotes_gpc was to prevent database injection attacks, because php developers, in the day of php 3, apparently couldn't be trusted to be smart enough to prevent it. It has nothing to do with text files, and should most certainly be disabled if possible. In php 6 magic_quotes_gpc won't even exist (along with register_globals), so this won't even be an issue. Darkwater's response is a viable method of removing the slashes if you can not disable the directive in php.ini. Indeed. =P Never rely on magic_quotes_gpc. Link to comment https://forums.phpfreaks.com/topic/109817-solved-readingwriting-to-text-file-help/#findComment-563589 Share on other sites More sharing options...
bluejay002 Posted June 12, 2008 Share Posted June 12, 2008 yeah... i forgot, my bad. i looked back with my previous codes... and i did not use addslashes() at all when saving to a file. thanks, Link to comment https://forums.phpfreaks.com/topic/109817-solved-readingwriting-to-text-file-help/#findComment-563596 Share on other sites More sharing options...
shazman Posted June 13, 2008 Author Share Posted June 13, 2008 Thanks. Everything is working great. Link to comment https://forums.phpfreaks.com/topic/109817-solved-readingwriting-to-text-file-help/#findComment-564408 Share on other sites More sharing options...
DarkWater Posted June 13, 2008 Share Posted June 13, 2008 Any time. Link to comment https://forums.phpfreaks.com/topic/109817-solved-readingwriting-to-text-file-help/#findComment-564411 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.