PHP REGEX-文本在换行符处由preg_split排列 [英] PHP REGEX - text to array by preg_split at line break

查看:111
本文介绍了PHP REGEX-文本在换行符处由preg_split排列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已编辑

需要有关拆分阵列的帮助

need help on split Array

数组示例:

 array (

           [0] =>
            :some normal text
            :some long text here, and so on... sometimes 
            i'm breaking down and...
            :some normal text
            :some normal text
        )

好,现在使用

preg_split( '#\n(?!s)#' ,  $text );

我明白了

[0] => Array
        (
            [0] => some normal text
            [1] => some long text here, and so on... sometimes
            [2] => some normal text
            [3] => some normal text
        )

我想要这个:

[0] => Array
        (
            [0] => some normal text
            [1] => some long text here, and so on... sometimes i'm breaking down and...
            [2] => some normal text
            [3] => some normal text
        )

正则表达式可以得到整行并且还能在换行时拆分!?

what Regex can get the entire line and also split at line break!?

推荐答案

即使您在字符串中嵌入了冒号(但不在行首),这也是一个有效的示例:

Here's an example that works, even if you have a colon character embedded inside the string (but not at start of the line):

$input = ":some normal text
:some long text here, and so on... sometimes
i'm breaking: down and...
:some normal text
:some normal text";

$array = preg_split('/$\R?^:/m', $input);
print_r($array);

结果:

Array
(
    [0] => some normal text
    [1] => some long text here, and so on... sometimes
           i'm breaking: down and...
    [2] => some normal text
    [3] => some normal text
)

这篇关于PHP REGEX-文本在换行符处由preg_split排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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