1

I have a text-block, with this content:

[/+]There is my first text[+/]. There is my second text.

[/+]There is my third text.[+/]
There is my fourth text.

...

Now, I want to split it into 2 strings:

  1. $str_1 = "There is my first text.";
  2. $str_2 = " There is my second text.
[/+]There is my third text.[+/]
There is my fourth text.

...";

Could you show me: "How to split a text-block into 2 strings, in PHP?".

tran_sang
  • 1
  • 3

2 Answers2

1

You can use explode function in php

explode($delimiter, "String");
Ray
  • 767
  • 4
  • 11
  • There are many ways to make that, 1. explode -2times or 3times 2. preg_split- $output = preg_split( '/(\[\/\+\]|\[\+\/\])/', "yout string"); – Ray Nov 21 '15 at 13:10
1

I'm not sure about your question but I think you might be looking for this

$str = "[/+]There is my first text[+/]. There is my second text.

[/+]There is my third text.[+/]
There is my fourth text.";

preg_match_all('/(\[\/\+])?([\w\s.]+)(\[\+\/])?/',$str,$m);

$str = "";
foreach($m[2] as $k => $v){
  ${"str".$k} = $v;
}

echo $str0."\n";
echo $str1."\n";
echo $str2."\n";
echo $str3."\n";

Demo

Narendrasingh Sisodia
  • 21,247
  • 6
  • 47
  • 54