[ create a new paste ] login | about

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

PHP, pasted on Jun 9:
<?php
$input = '
html    text/html; charset=UTF-8
css     text/css
js      application/x-javascript

jpeg    image/jpeg
jpg     image/jpeg
png     image/png';

$result = array();
$input = str_replace("\r\n", "\n", $input);
$rows = explode("\n", $input);
foreach($rows as $row) {
    $row = trim($row);
    if (!empty($row)) {
        $first_space_position = strpos($row, ' ');
        $key = trim(substr($row, 0, 8));
        $val = trim(substr($row, 8));
        $result[$key] = $val;
    }
}

var_export($result);


Output:
1
2
3
4
5
6
7
8
array (
  'html' => 'text/html; charset=UTF-8',
  'css' => 'text/css',
  'js' => 'application/x-javascript',
  'jpeg' => 'image/jpeg',
  'jpg' => 'image/jpeg',
  'png' => 'image/png',
)


Create a new paste based on this one


Comments: