【发布时间】:2019-08-07 06:47:32
【问题描述】:
我正在使用 preg_split 来拆分以下字符串:
$string = 'textarea name="custom_field" label="Space space space" column="1/2"';
$preg_split = preg_split("/\s(?![\w\s]+\")/", $string);
echo '<pre>',print_r($preg_split,1),'</pre>';
此代码给出以下结果:
Array
(
[0] => textarea
[1] => name="custom_field"
[2] => label="Space space space"
[3] => column="1/2"
)
这里一切正常。
但是,如果我添加带有空格的土耳其语字符,它将无法正常工作:
$string = 'textarea name="custom_field" label="âçğı İîöşüû" column="1/2"';
$preg_split = preg_split("/\s(?![\w\s]+\")/", $string);
echo '<pre>',print_r($preg_split,1),'</pre>';
它用土耳其字符分割字符串的中间:
Array
(
[0] => textarea
[1] => name="custom_field"
[2] => label="âçğı
[3] => İîöşüû"
[4] => column="1/2"
)
如何检测 preg_split 中的土耳其语字符并将它们保存在一个数组值中?像这样:
Array
(
[0] => textarea
[1] => name="custom_field"
[2] => label="âçğı İîöşüû"
[3] => column="1/2"
)
【问题讨论】:
标签: php preg-split