W
W
WQP2014-12-14 16:16:26
PHP
WQP, 2014-12-14 16:16:26

How to split text correctly?

Hello, there is text:

img32.jpg | img75.jpg
img72.jpg | img01.jpg
...
img77.jpg | img80.jpg

How to split it so that you get an array of the form:
array(
    '0' => array(
        '1'   => 'img32.jpg', 
        '2'    => 'img75.jpg',
                     ),
   '1' => array(
        '1'   => 'img72.jpg', 
        '2'    => 'img01.jpg',
                     ),
...
   'N' => array(
        '1'   => 'img77.jpg', 
        '2'    => 'img80.jpg',
                     ),
    )

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel, 2014-12-14
@WQP

$result = array();
$lines = explode("\n", $text);
foreach($lines as $line){
 $elems = explode(" | ", $line);
 array_push($result, array($elems[0], $elems[1])); 
}

F
FanatPHP, 2014-12-14
@FanatPHP

Still, toaster-driven development is unbeatable.
It is based on the desperate desire of shitcoders to assert themselves by proving to others that they can write shitcode too! It is for this tender place that lazy beggars take them.
At the same time, no one mastered the regular season :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question