fontSize=16.0, fontFamily=sans, align=0, color=FF0000, text="foo, bar"
and I need match for spit. Output will be
array(
'fontSize'=>'16.0',
'fontFamily'=>'sans',
'align'=>'0',
'color'=>'FF0000',
'text'=>'foo, bar'
);
I tried next, but it was bad:
preg_spit("~[\s]="?[\s]"?,~", $string);
Just split your input string according to the below regex,
,\s(?![^=]*")
<?php
$str = 'fontSize=16.0, fontFamily=sans, align=0, color=FF0000, text="foo, bar"';
$regex = '~,\s(?![^=]*")~';
$splits = preg_split($regex, $str);
print_r($splits);
?>
Output:
Array
(
[0] => fontSize=16.0
[1] => fontFamily=sans
[2] => align=0
[3] => color=FF0000
[4] => text="foo, bar"
)
Regular Expression:
, ','
\s whitespace (\n, \r, \t, \f, and " ")
(?! look ahead to see if there is not:
[^=]* any character except: '=' (0 or more
times)
" '"'
) end of look-ahead
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다