I need to parse a text file into php array. Here is my text file :
file: slide1.jpg | title: Title here | description: Aenean eleifend ultrices leo at venenatis. Suspendisse luctus | crop: top
file: slide2.jpg | description: Phasellus ac tortor ut dolor blandit tincidunt | title: Nullam cursus | crop: bottom
file: slide3.jpg | title: Hendrerit lacinia nisl | description: Tortor ut dolor blandit tincidunt | crop: bottom
file: slide4.jpg | title: Morbi hendrerit lacinia nisl | description: Maecenas venenatis lectus vitae | crop: left
I want to parse it into such structured array :
array(4) {
"slide1.jpg" => array (
"title" => "Title here",
"description" => "Aenean eleifend ultrices leo at venenatis. Suspendisse luctus",
"crop" => "top"
),
"slide2.jpg" => array (
"title" => "Nullam cursus",
"description" => "Phasellus ac tortor ut dolor blandit tincidunt",
"crop" => "top"
),
"slide3.jpg" => array (
"title" => "Hendrerit lacinia nisl",
"description" => "Tortor ut dolor blandit tincidunt",
"crop" => "top"
),
"slide4.jpg" => array (
"title" => "Morbi hendrerit lacinia nisl",
"description" => "Maecenas venenatis lectus vitae",
"crop" => "top"
)
}
I tried with a many repetitive foreach statements but it was not so efficient and the code got very lengthy. Does anybody know a way to achieve it simpler.
|SV.