我想獲得這個文本中的每個字,但需要體貼逗號作爲單獨的詞,在PHP中:PHP單獨的文本,但體貼逗號作爲字
我輸入文本:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
我想數組:
array[0] => "Lorem"
array[1] => "ipsum"
array[2] => "dolor"
array[3] => "sit"
array[4] => "amet"
array[5] => ","
array[6] => "consectetuer"
array[7] => "adipiscing"
array[8] => "elit"
array[9] => "."
什麼我得到explode(" ", $text)
是:
array[0] => "Lorem"
array[1] => "ipsum"
array[2] => "dolor"
array[3] => "sit"
array[4] => "amet,"
array[5] => "consectetuer"
array[6] => "adipiscing"
array[7] => "elit."
你能幫我嗎? TIA
使用'preg_match_all(「/ \ w + |,| \ ./」,$ str,$ matches)' – Mohammad
@Mohammad https://meta.stackexchange.com/questions/230676/hey-you-yeah-you -post-your-answers-as-answers-not-comments評論將被用於要求澄清或OP中的其他細節。請不要回覆評論(並請刪除您評論的答案)。 – mickmackusa