PHP使用正则表达式使字符串爆炸 [英] PHP explode string using a regular expression

查看:76
本文介绍了PHP使用正则表达式使字符串爆炸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很长的字符串,由一系列用单引号分隔的句子组成.

I have a long string consisting of a series of sentences separated by a single quote.

示例:

This\'s sentence number 1'This\'s sentence number 2'

请注意,字符串在句子本身的单引号部分已被转义.我需要使用单引号引起爆炸,而不是转义的单引号.

Notice that the string has single quotes part of the sentence itself which are escaped. I need to explode the string using single quote, but not the escaped single quote.

输出应为:

Array{
      [0]=>This\'s sentence number 1
      [1]=>This\'s sentence number 2
}

基本上,我需要爆炸{'}上的字符串,而不是{\'}. 预先感谢.

Basically I need to explode the string on { ' }, but not { \' }. Thanks in advance.

推荐答案

尝试一下:

print_r(preg_split("/(?<!\\\)\'/", "This\'s sentence number 1'This\'s sentence number 2'"));

这篇关于PHP使用正则表达式使字符串爆炸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆