When to use addslashes() and stripslashes()

When to use addslashes() and stripslashes()

by Gustav W Delius -
Number of replies: 6
I have added a page to the Developer part of MoodleDocs explaining when to use addslashes() and stripslashes(). It is quite simple but it is easy to get it wrong.

I also fixed some places in the code where things went wrong, for example in blog posts. Also for some reason print_textarea() was stripping slashes from the text that was sent to the html area but not from the text that was sent to standard text areas. I have changed that so that it never strips slashes.
Average of ratings: -
In reply to Gustav W Delius

Re: When to use addslashes() and stripslashes()

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
I was just about to fix the incorrect use of slashes in the 1.7 blog, thanks smile
In reply to Gustav W Delius

Re: When to use addslashes() and stripslashes()

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
There should also be information about always using s() and p() to output strings from the database.

With luck this will all be less of an issue in 1.8, as we're planning to add "prepared statements" to the database library functions and will be expecting everything to be not slashed all the time.

P.S. Remember, the namespace is Development not Developer, I see Helen has already fixed this page. approve
In reply to Martin Dougiamas

Re: When to use addslashes() and stripslashes()

by Shamim Rezaie -
Hi
Are those addslashes() and stripslashes() still required?
In reply to Shamim Rezaie

Re: When to use addslashes() and stripslashes()

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
In Moodle 1.9 development: yes.
In Moodle 2.0 (HEAD) development: no (and see other documentation on changes to database system).

--sam