Special character conversion in PHP

Source: Internet
Author: User

<?php
  function check_form($form) {
   if(!get_magic_quotes_gpc()) { //get_magic_quotes_gpc()这个函数是检测在PHP.INI中magic_quotes_gpc是否设置
    for($i=0;$i<count($form);$i++){   //count是计算变量中元素的个数,从第一个开始判断是不是特殊字符
  $form[$i]=addslashes($form[$i]); //如果是特殊字符则用addslashes()函数转换
}
   }
   return $form; //返回转换好的变量
  }
?>

Note: In PHP.ini, MAGIC_QUOTES_GPC and Magic_quotes_runtime are encountered with a special character automatic conversion, if set to on, automatic conversion, if off is the opposite. The difference is that the former is used when the request starts, the latter is used to read data from a file or execute exec () results or from SQL queries, each time the script accesses the data generated in the running state.

Write here suddenly remembered there is a setting, and the above irrelevant, just think up, conveniently recorded here error_reporting (0); setting does not display page error messages.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.