You are here: Home Programming PHP How to use PHP addslashes() Function

How to use PHP addslashes() Function

 

 

 

How to use PHP addslashes () Function

The addslashes() function returns a string with backslashes in front of predefined characters. PHP runs addslashes() on all GET, POST, and COOKIE data by default. Therefore you should not use addslashes() on strings that have already been escaped, this will cause double escaping. The function get_magic_quotes_gpc() can be used to check this.

 

This function can be used to prepare a string for storage in a database and database queries.

 

The predefined characters  are:
- single quote (')
- double quote (")
- backslash (\)
- NULL

Syntax

addslashes(string)

Parameter

String is a required field

 

Problem

<?php
$str = "Who's Khabza?";
echo $str . " This is not safe in a database query.<br />";
echo addslashes($str) . " This is safe in a database query.";
?>

 

Solution

Who's Khabza? This is not safe in a database query.
Who\'s Khabza? This is safe in a database query.

 

 

 


Clientele

 

SIGN UP RIGHT NOW FOR EMAIL UPDATES

Share this post


blog comments powered by Disqus

Print PDF

HTML Codes
opinions powered by SendLove.to

Our valuable member Khabza has been with us since Thursday, 08 July 2010.

Show Other Articles Of This Author

Back to top
SA Topsites :: Simphiwe - Find me on Bloggers.com

Copyright © Green IT Web - Blog by Khabza in Cape Town 2012

Template by Joomla 1.7 Templates & Szablony Joomla.