PHP addslashes function for filtering strings

巴扎黑
Release: 2023-03-02 17:58:01
Original
1831 people have browsed it

For data security and preventing injection, it is necessary to filter the string obtained by $_GET. At first, I wrote a filtering function by myself. Later, I saw a filtering function that comes with PHP, so I recommended addslashes to everyone.
An example of using addslashes() is when you are entering data into a database. For example, inserting the name O'reilly into the database requires escaping it. Most databases use as escape character: O'reilly. This puts the data into the database without inserting extra . When the PHP directive magic_quotes_sybase is set to on, it means that inserting ' will be escaped with '.
Example:

 <?php 
   $str = "Is your name O&#39;reilly?"; 
   // 输出:Is your name O\&#39;reilly? 
   echo addslashes($str); 
  ?>
Copy after login


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!