<?php
mb_internal_encoding('UTF-8');
function get_goods_info($str) {
$ret = array();
if (($sharp_pos = strpos($str, '#')) === false) {
return false;
}
$ret['description'] = substr($str, 0, $sharp_pos);
$str = substr($str, $sharp_pos + 1);
if (($iro_pos = mb_strpos($str, '色')) === false) {
return false;
}
$ret['color'] = str_replace('/', '色 ', ltrim(mb_substr($str, 0, $iro_pos + 1)));
$ret['weight'] = ltrim(mb_substr($str, $iro_pos + 1));
return $ret;
}
var_dump(
get_goods_info('光の3原色から選べます# 赤/青/黄色 210g'),
get_goods_info('# 茶/カーキ/黄/緑色 100g'),
get_goods_info('1色でもOK・なんとなくkgにも対応# 肌色 2.5kg'),
get_goods_info('これには# マッチしません ')
);
preferences:
48.29 ms | 402 KiB | 5 Q