Home Backend Development PHP Tutorial php有关问题解决

php有关问题解决

Jun 13, 2016 am 10:47 AM
escape file

php问题解决

?

php问题解决:

?

1: 字符串转义函数:?

?

?1>插入mysql数据库转义函数: mysqli_escape_string();

?2>addslashes() 使用反斜线引用字符串

? ? 描述:返回字符串,该字符串为了数据库查询语句等的需要在某些字符前加上了反斜线。

? ? ? ? ? 这些字符是单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)

? ?须注意:默认情况下,PHP 指令 magic_quotes_gpc 为 on,它主要是对所有的 GET、POST 和 COOKIE 数据自动运行 addslashes()。

不要对已经被 magic_quotes_gpc 转义过的字符串使用 addslashes(),因为这样会导致双层转义。

遇到这种情况时可以使用函数 get_magic_quotes_gpc() 进行检测。

?3>stripslashes()?

本函数可去掉字符串中的反斜线字符。若是连续二个反斜线,则去掉一个,留下一个。若只有一个反斜线,就直接去掉。

?4> htmlspecialchars ? ? ? ? ? ?把一些预定义的字符转换为 HTML 实体

?5> htmlspecialchars_decode ? ? 把一些预定义的 HTML 实体转换为字符

?6> html_entity_decode() ? ? ? ?把 HTML 实体转换为字符

?7> htmlentities() ? ? ? ? ? ? ?把字符转换为 HTML 实体

?

?

2: 文件http下载方式:

header( "Content-type: application" );

header( "Content-Disposition: attachment; filename=$filename" );

header( "Content-Description: PHP Generated Data\n\n\n" );

echo $str_contents;

?

?

3: file函数

file_get_contents();

将整个文件读入一个字符串?

? 语法:file_get_contents ( string filename [, bool use_include_path [, resource context [, int offset [, int maxlen]]]] )

和 file() 一样,只除了 file_get_contents() 把文件读入一个字符串。将在参数 offset 所指定的位置开始读取长度为 maxlen 的内容。

如果失败,file_get_contents() 将返回 FALSE。?

file_get_contents() 函数是用来将文件的内容读入到一个字符串中的首选方法。如果操作系统支持还会使用内存映射技术来增强性能。?

注意:?

如果要打开有特殊字符的 URL (比如说有空格),就需要使用 urlencode() 进行 URL 编码。?

注意:?

context 参数可以用 NULL 来忽略。

?

?

4: 转向:

header("location:index.php")

?

5: JavaScript的URL编码方法比较:escape、encodeURI和encodeURIComponent

javascript中存在几种对URL字符串进行编码的方法:escape(),encodeURI(),以及encodeURIComponent()。这几种编码所起的作用各不相同。

escape()方法:

采用ISO Latin字符集对指定的字符串进行编码。所有的空格符、标点符号、特殊字符以及其他非ASCII字符都将被转化成%xx格式的字符编码(xx等于该字符在字符集表里面的编码的16进制数字)。比如,空格符对应的编码是%20。 不会被此方法编码的字符: @ * / +

encodeURI()方法:

把URI字符串采用UTF-8编码格式转化成escape格式的字符串。 不会被此方法编码的字符:! @ # $& * ( ) = : / ; ? + ‘

encodeURIComponent()方法:

把URI字符串采用UTF-8编码格式转化成escape格式的字符串。与encodeURI()相比,这个方法将对更多的字符进行编码,比如 / 等字符。所以如果字符串里面包含了URI的几个部分的话,不能用这个方法来进行编码,否则 / 字符被编码之后URL将显示错误。不会被此方法编码的字符:! * ( ) ‘

因此,对于中文字符串来说,如果不希望把字符串编码格式转化成UTF-8格式的(比如原页面和目标页面的charset是一致的时候),只需要使用 escape。如果你的页面是GB2312或者其他的编码,而接受参数的页面是UTF-8编码的,就要采用encodeURI或者 encodeURIComponent。

另外,encodeURI/encodeURIComponent是在javascript1.5之后引进的,escape则在javascript1.0版本就有。

?

?

if( function_exists('mb_detect_encoding') ){

$file_encoding = ?mb_detect_encoding($tdv,array("GB2312","GBK","UTF-8"));

if( strtoupper($file_encoding) !=='GB2312' ){

$tdv = iconv("UTF-8","GB2312//IGNORE",$tdv);

}

}

?

?

?

p

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hongmeng native application random poetry Hongmeng native application random poetry Feb 19, 2024 pm 01:36 PM

To learn more about open source, please visit: 51CTO Hongmeng Developer Community https://ost.51cto.com Running environment DAYU200:4.0.10.16SDK: 4.0.10.15IDE: 4.0.600 1. To create an application, click File- >newFile->CreateProgect. Select template: [OpenHarmony] EmptyAbility: Fill in the project name, shici, application package name com.nut.shici, and application storage location XXX (no Chinese, special characters, or spaces). CompileSDK10, Model: Stage. Device

Use java's File.length() function to get the size of the file Use java's File.length() function to get the size of the file Jul 24, 2023 am 08:36 AM

Use Java's File.length() function to get the size of a file. File size is a very common requirement when dealing with file operations. Java provides a very convenient way to get the size of a file, that is, using the length() method of the File class. . This article will introduce how to use this method to get the size of a file and give corresponding code examples. First, we need to create a File object to represent the file we want to get the size of. Here is how to create a File object: Filef

How to convert php blob to file How to convert php blob to file Mar 16, 2023 am 10:47 AM

How to convert php blob to file: 1. Create a php sample file; 2. Through "function blobToFile(blob) {return new File([blob], 'screenshot.png', { type: 'image/jpeg' })} ” method can be used to convert Blob to File.

Rename files using java's File.renameTo() function Rename files using java's File.renameTo() function Jul 25, 2023 pm 03:45 PM

Use Java's File.renameTo() function to rename files. In Java programming, we often need to rename files. Java provides the File class to handle file operations, and its renameTo() function can easily rename files. This article will introduce how to use Java's File.renameTo() function to rename files and provide corresponding code examples. The File.renameTo() function is a method of the File class.

Use java's File.getParentFile() function to get the parent directory of the file Use java's File.getParentFile() function to get the parent directory of the file Jul 27, 2023 am 11:45 AM

Use java's File.getParentFile() function to get the parent directory of a file. In Java programming, we often need to operate files and folders. When we need to get the parent directory of a file, we can use the File.getParentFile() function provided by Java. This article explains how to use this function and provides code examples. File class in Java is the main class used to operate files and folders. It provides many methods to obtain and manipulate file properties

Use java's File.getParent() function to get the parent path of the file Use java's File.getParent() function to get the parent path of the file Jul 24, 2023 pm 01:40 PM

Use java's File.getParent() function to get the parent path of a file. In Java programming, we often need to operate files and folders. Sometimes, we need to get the parent path of a file, which is the path of the folder where the file is located. Java's File class provides the getParent() method to obtain the parent path of a file or folder. The File class is Java's abstract representation of files and folders. It provides a series of methods for operating files and folders. Among them, get

How to delete a file or directory using File.delete() method in Java? How to delete a file or directory using File.delete() method in Java? Nov 18, 2023 am 08:02 AM

How to delete a file or directory using File.delete() method in Java? Overview: In Java, we can delete a file or directory using the delete() method of the File class. This method is used to delete the specified file or directory. However, it should be noted that this method can only delete empty directories or files that are not opened by other programs. If file or directory deletion fails, you can find the specific reason by catching IOException. Step 1: Import related packages First, we need

WebView File Domain Origin Policy Bypass Vulnerability Example Analysis WebView File Domain Origin Policy Bypass Vulnerability Example Analysis May 15, 2023 am 08:22 AM

Basic knowledge of the Android architecture. Kernel kernel layer vulnerabilities are extremely harmful. The versatile drivers are numerous and complex, and there may also be many vulnerabilities. Libraries system runtime library layer system middleware provides runtime libraries including libc, WebKit, SQLite, etc. AndroidRunTimeDalvik virtual The machine and kernel library FrameWork application framework layer provides a series of services and API interfaces Activity Manager Content Provider View Resource Manager Notification Manager Application Application Layer System Application Home Screen Home, Contact Contact, Phone Phone, Browser Others Application developers use the application framework layer to

See all articles