PHP addslashes() Function
Complete PHP String Reference
Definition and Usage
The addslashes() function returns a string with backslashes in front of
predefined characters.
The predefined characters are:
- single quote (')
- double quote (")
- backslash (\)
- NULL
Syntax
| Parameter |
Description |
| string |
Required. Specifies the string to check |
Tips and Notes
Tip: This function can be used to prepare a string for storage in a
database and database queries.
Note: 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.
Example
In this example we will add backslashes to the predefined characters in a string:
<?php
$str = "Who's Kai Jim?";
echo $str . " This is not safe in a database query.<br />";
echo addslashes($str) . " This is safe in a database query.";
?>
|
The output of the code above will be:
Who's Kai Jim? This is not safe in a database query.
Who\'s Kai Jim? This is safe in a database query.
|
Complete PHP String Reference
Whether you're new to XML or already an advanced user, the user-friendly views
and powerful entry helpers, wizards, and debuggers in XMLSpy are designed to
meet your XML and Web services development needs from start to finish.
- XML editor
- Graphical XML Schema / DTD editors
- XSLT 1.0/2.0 editor, debugger, profiler
- XQuery editor, debugger, profiler
- Support for Office Open XML (OOXML)
- Graphical WSDL editor & SOAP debugger
- Java, C#, C++ code generation
- And much more!
Download a free 30-day trial today!
Click to see a demo!
Learn what’s new in v2008
 |
|
Get Your Diploma!
W3Schools' Online Certification Program is the perfect solution for busy
professionals who need to balance work, family, and career building.
The HTML Certificate is for developers who want to document their knowledge of HTML, XHTML, and CSS.
The ASP Certificate is for developers who want to document their knowledge of ASP, SQL, and ADO.
|
|