[ create a new paste ] login | about

Link: http://codepad.org/1DFfyNni    [ raw code | output | fork ]

PHP, pasted on Sep 18:
1
2
3
4
5
6
7
8
9
10
11
12
<?php
$string = "Topher:Topher1234@mac.com\nElvis:elvispresley@gmail.com\nMarilyn:marilyn.monroe@hotmail.com";
    $string = explode("\n", $string);
    $result = array(); # or your existing array
    foreach($string as $chunk){
            $to_array = new stdClass();
            $to_array->id = null;
            $to_array->surname = null;
            list($to_array->name, $to_array->email) = explode(':', $chunk);
            $result[] = $to_array;
    }
    print_r($result);


Output:
Array
(
    [0] => stdClass Object
        (
            [id] => 
            [surname] => 
            [email] => Topher1234@mac.com
            [name] => Topher
        )

    [1] => stdClass Object
        (
            [id] => 
            [surname] => 
            [email] => elvispresley@gmail.com
            [name] => Elvis
        )

    [2] => stdClass Object
        (
            [id] => 
            [surname] => 
            [email] => marilyn.monroe@hotmail.com
            [name] => Marilyn
        )

)


Create a new paste based on this one


Comments: