我将使用 preg_split 函数来拆分以下字符串:
这段代码会产生以下结果:
它使用土耳其字符将字符串中间分割成两部分:
我该如何在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"
)