栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

PHP爆炸字符串,但将引号中的单词视为单个单词

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

PHP爆炸字符串,但将引号中的单词视为单个单词

您可以使用

preg_match_all(...)

$text = 'Lorem ipsum "dolor sit amet" consectetur "adipiscing \"elit" dolor';preg_match_all('/"(?:\\.|[^\\"])*"|S+/', $text, $matches);print_r($matches);

会产生:

Array(    [0] => Array        ( [0] => Lorem [1] => ipsum [2] => "dolor sit amet" [3] => consectetur [4] => "adipiscing "elit" [5] => dolor        ))

如您所见,它还考虑了带引号的字符串中的转义引号。

编辑

简短说明:

"# match the character '"'(?:         # start non-capture group 1   \        #   match the character ''  .         #   match any character except line breaks  |         #   OR  [^\"]    #   match any character except '' and '"')*          # end non-capture group 1 and repeat it zero or more times"# match the character '"'|# ORS+         # match a non-whitespace character: [^s] and repeat it one or more times

并且在匹配

%22
而不是双引号的情况下,您可以执行以下操作:

preg_match_all('/%22(?:\\.|(?!%22).)*%22|S+/', $text, $matches);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/442962.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号