❮ PHP String Reference
Example
Decode a quoted-printable string to an 8-bit ASCII string:
The browser output of the code above will be:
Hello world.
The HTML output of the code above will be [View Source]:
Hello
world.
Try it Yourself »
Definition and Usage
The quoted_printable_decode[] function decodes a quoted-printable string to an 8-bit ASCII string.
Tip: Data encoded in quoted-printable are unlikely to be modified by mail transport. A text which is entirely US-ASCII may be encoded in quoted-printable to ensure the integrity of the data should the message pass through a character-translating, or line-wrapping gateway.
Syntax
quoted_printable_decode[string]
Parameter Values
ParameterDescriptionstring | Required. Specifies the quoted-printable string to be decoded |
Technical Details
Return Value:PHP Version:Returns the 8-bit ASCII string |
4+ |
❮ PHP String Reference
[PHP 4, PHP 5, PHP 7, PHP 8]
addslashes — Quote string with slashes
Description
addslashes[string $string]: string
- single quote [']
- double quote ["]
- backslash [\]
- NUL [the NUL byte]
A use case of addslashes[] is escaping the aforementioned characters in a string that is to be evaluated by PHP:
if you need to quote SQL strings it's
Notice that there are no quotes around the ?s. It handles that for you automatically. It's guaranteed to be safe
for your database. [Just ' on oracle, \ and ' on PostgreSQL, but you don't even have to think about it.]
Plus, if the database supports prepared statements [the soon-to-be-released PostgreSQL 7.3, Oracle, etc], several executes on the same prepare can be faster, since it can reuse the same query plan. If it doesn't [MySQL, etc], this way falls back to quoting code that's specifically written for your database, avoiding the problem I mentioned above.
[Pardon my syntax if it's off. I'm not really a PHP programmer; this is something I know from similar things in Java, Perl, PL/SQL, Python, Visual Basic, etc.]
luciano at vittoretti dot com dot br ¶
16 years ago
Note, this function wont work with mssql or access queries.
Use the function above [work with arrays too].
function addslashes_mssql[$str]{
if [is_array[$str]] {
foreach[$str AS $id => $value]
{
$str[$id] = addslashes_mssql[$value];
}
} else {
$str = str_replace["'", "''", $str];
}
return $str;
}
function stripslashes_mssql[$str]{
if [is_array[$str]] {
foreach[$str AS $id => $value] {
$str[$id] =
stripslashes_mssql[$value];
}
} else {
$str = str_replace["''", "'", $str];
}
return $str;
}
Lars ¶
10 years ago
Even for simple json string backslash encodings, do not use this function. Some tests may work fine, but in json the single quote ['] must not be escaped.
joechrz at gmail dot com ¶
16 years ago
Here's an example of a function that prevents double-quoting, I'm surprised noone has put something like this up yet... [also works on arrays]
DarkHunterj ¶
13 years ago
Based on:
Danijel Pticar
05-Aug-2009 05:22
I recommend this extended version, to replace addslashes altogether[works for both strings and arrays]:
baburaj dot ambalam at gmail dot com ¶
2 years ago
escape '$' using backslash '\$'