How to use php quotemeta function?

藏色散人
Release: 2023-02-22 22:20:01
Original
2948 people have browsed it

php quotemeta函数用于在字符串中某些预定义的字符前添加反斜杠,其语法是quotemeta(string),参数string必需,指规定要检查的字符串。

How to use php quotemeta function?

php quotemeta函数怎么用?

定义和用法

quotemeta() 函数在字符串中某些预定义的字符前添加反斜杠。

预定义的字符:

● 句号(.)

● 反斜杠(\)

● 加号(+)

● 星号(*)

● 问号(?)

● 方括号([])

● 脱字号(^)

● 美元符号($)

● 圆括号(())

提示:该函数可用于转义拥有特殊意义的字符,比如 SQL 中的 ( )、[ ] 以及 * 。

注释:该函数是二进制安全的。

语法

quotemeta(string)
Copy after login

参数

string 必需。规定要检查的字符串。

返回值: 返回引用元字符的字符串。

PHP 版本: 4+

例子 1

在多个预定义字符前添加反斜杠:

"; echo quotemeta($str2)."
"; echo quotemeta($str3)."
"; echo quotemeta($str4)."
"; echo quotemeta($str5)."
"; ?>
Copy after login

输出:

1 \+ 1 = 2 1 \* 1 = 1 Could you borrow me 5\$\? Are you not e The caret \[ \^ \] Looks like a hat!
Copy after login

例子 2

在预定义字符前添加反斜杠:

Copy after login

输出:

Hello world\. \(can you hear me\?\)
Copy after login

The above is the detailed content of How to use php quotemeta function?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
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!