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:
|
array (
'html' => 'text/html; charset=UTF-8',
'css' => 'text/css',
'js' => 'application/x-javascript',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'png' => 'image/png',
)
|
|