带有空格和土耳其字符的PHP preg_分割字符串
我使用preg_split拆分以下字符串:带有空格和土耳其字符的PHP preg_分割字符串,php,preg-split,Php,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>'; 这里一切都很好 但是,如果我添加了带空格的土耳其语字符,则无法按
$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="âçğı
[3] => İîöşüû"
[4] => column="1/2"
)
如何检测preg_split中的土耳其字符并将其保存在一个数组值中?像这样:
只需使用'u'修饰符(用于utf8字符串),如
$string='textarea name=“custom_field”label=“çāıİîşā”column=“1/2”;
$preg\u split=preg\u split(“/\s(?[\w\s]+\”)/u“,$string);
回音“”,打印($preg\u split,1),“”;
$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"
)
Array
(
[0] => textarea
[1] => name="custom_field"
[2] => label="âçğı İîöşüû"
[3] => column="1/2"
)
$string = 'textarea name="custom_field" label="âçğı İîöşüû" column="1/2"';
$preg_split = preg_split("/\s(?![\w\s]+\")/u", $string);
echo '<pre>',print_r($preg_split,1),'</pre>';