作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
php 函数 preg_quote
转义这些字符 . \ + * ? [ ^ ] $ ( ) { } = ! < > | : -
请问我可以用什么来转义这些字符:+ - && || ! ( ) { } [ ] ^ " ~ * ? : /
已编辑(按“待定”要求):
我正在实现 Solr
搜索并显示:
Solr gives the following characters special meaning when they appear in a query:
+ - && || ! ( ) { } [ ] ^ " ~ * ? : /To make Solr interpret any of these characters literally, rather as a special character, precede the character with a backslash character .
最佳答案
这可能对您有帮助:
<?php
$subject = "+ - && || ! ( ) { } [ ] ^ \" ~ * ? : /";
$result = preg_replace('%([+\-&|!(){}[\]^"~*?:/]+)%', '\\\\$1', $subject);
echo $result;
?>
关于php - 如何只转义某些字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23265654/
我是一名优秀的程序员,十分优秀!