gpt4 book ai didi

php - 如何只转义某些字符

转载 作者:可可西里 更新时间:2023-10-31 22:54:43 25 4
gpt4 key购买 nike

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;
?>

http://ideone.com/EYV1ID

关于php - 如何只转义某些字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23265654/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com