我想分割一个字符串到数组中。我希望单词和元字符在数组中分开。 像这样:php spltting字符串与元数组
$string = 'This is a string? Or an array?';
我想:
array[0] = 'This',
array[1] = 'is',
array[2] = 'a',
array[3] = 'string',
array[4] = '?',
array[5] = 'Or',
array[6] = 'etc';
我知道,必须使用preg_split
。但我可以管理只选择字符串或没有字符串。我在互联网上搜索,但我只能找到没有元字符的例子。
我希望有人知道答案,因为我在preg_spilt
的分隔符。
谢谢你的时间。
什么是元字符?你的意思是标点符号吗? – WillardSolutions
感谢您的回复。是的,我想要所有的:标点符号问号,等等。我必须做一个听写程序,检查是否拼写正确。而且标点符号位于正确的位置。 – Overste