I got a string like this:
== Paragraph ==
=== title 1 ===
content
=== Title 2 ===
other content
== Paragraph 2 ==
=== asd1 ===
dfdsfdsfdsfdsfdsfsdfdsf
=== asd2 ===
fgdfgfdgfdgfdgfdgfdgfdg
I'm trying to parse it into array like this:
$arr = array(
array("title"=>"Paragraph", "content" => "=== title 1 ===
content
=== Title 2 ===
other content "),
array("title"=>"Paragraph 2", "content" => "=== asd1 ===
dfdsfdsfdsfdsfdsfsdfdsf
=== asd2 ===
fgdfgfdgfdgfdgfdgfdgfdg"));
I've tried this expession for getting paragraph names:
preg_match_all("@== (.*?) ==.*?@is", $data, $paragraphs);
but this expresion isn't working as I want, because it doesn't match the whole paragraph the output is like this and it doesn't get the contents:
Array
(
[0] => Paragraph
[1] => title 1
[2] => Title 2
[3] => Paragraph 2
[4] => asd1
[5] => asd2
)
I have also tried ( nl2br cuz I don't know how to use new line in regex )
$data = nl2br($data);
preg_match_all("@== (.*?) ==<br />.*?@is", $data, $paragraphs);
but the result is something like this:
[0] => Array
(
[0] => == Paragraph == <br />
=== title 1 ===<br />
content<br />
<br />
=== Title 2 ===<br />
other content <br />
<br />
== Paragraph 2 ==<br />
)
I'm not understanding the regular expresions good and I can't figure out how to solve my problem.