我有這個簡單的問題太麻煩了字母對:將一個字符串分解成2個字符值的陣列,即使preg_split串入
$string = 'abcdefgh';
// With the correct regex, should return ['ab','cd','ef','gh'];
$array = preg_split("/?????/",$string);
有什麼混賬正則表達式?
我有這個簡單的問題太麻煩了字母對:將一個字符串分解成2個字符值的陣列,即使preg_split串入
$string = 'abcdefgh';
// With the correct regex, should return ['ab','cd','ef','gh'];
$array = preg_split("/?????/",$string);
有什麼混賬正則表達式?
改爲使用str_split()
。
$chunks = str_split($string, 2);
提示:如果拆分上的字符,就結束了4個元素是空白
例如陣列。
/../i
我不認爲使preg_split是你想要的,也許preg_match_all
?例如。
$cnt = preg_match_all('/../i', $string, $matches);
是的,這正是發生了什麼事情。啊,這非常有幫助。謝謝! – Ben 2011-05-25 02:22:57
你的歡迎,與str_split(下)我還評論說,你必須小心UTF-8字符作爲str_split是由字節長度 – 2011-05-25 02:25:53
+1打我和堅持從正則表達式! – 2011-05-25 02:10:08
再次,@alex。快捷方便。乾杯。 – Ben 2011-05-25 02:10:25