ຫົວຂໍ້ PHP addslashes() ອາການ
Example
Add a backslash before each double quote ("):
<?php $str = addslashes('Shanghai is the "biggest" city in China.'); echo($str); ?>
Definition and Usage
The addslashes() function returns a string with a backslash added before the predefined characters.
The predefined characters are:
- Single quotes (')
- Double quotes (")
- Backslash (\)
- NULL
Tip:ຫົວຂໍ້ບູລິບບບນີ້ສາມາດນຳໃຊ້ເພື່ອການກະກຽມຄຳທີ່ບັນຈຸພາຍໃນຖານຂໍ້ມູນ ແລະ ຄຳທີ່ຖືກນຳໃຊ້ເພື່ອການສອບສວນຖານຂໍ້ມູນ.
Note:ໂດຍຜູ້ຮັບປະກັນໂດຍກົງ, PHP ຈະກະຕຸ້ນ addslash() ອັດຕະພາບ GET, POST ແລະ COOKIE ຂໍ້ມູນ. ບໍ່ຄວນນໍາໃຊ້ addslash() ຕໍ່ຄຳທີ່ໄດ້ຖືກຫຼຸດອອກ, ຍ້ອນວ່າຈະເປັນການຫຼຸດອອກຂອງຄຳທີ່ສອງຊົ່ວຄາວ. ໃນກໍລະນີດັ່ງກ່າວ, ຈະສາມາດໃຊ້ຫົວຂໍ້ get_magic_quotes_gpc() ສຳລັບການກວດສອບ.
Syntax
addslashes(string)
Parameter | ການອະທິບາຍ |
---|---|
string | ຈໍາຕະລາງ. ປະກອບຄຳທີ່ຈະຫຼຸດອອກ. |
ຂໍ້ມູນດ້ານເຕັກນິກ
ຄຳຕອບວ່າ: | ກັບຄືນຄຳທີ່ໄດ້ຖືກຫຼຸດອອກ. |
PHP Version: | 4+ |
ບັນທັດຫຼາຍຫຼາຍ
ບັນທັດ 1
ສະເໜີກົດດັນສະເພາະໃຫ້ກັບຄຳຂອງ
<?php $str = "Who's Bill Gates?"; echo $str . " This is not safe in a database query.<br>"; echo addslashes($str) . " This is safe in a database query."; ?>