我有一个很长的文本(3600个句子),我想改变随机句子的顺序.有一些简单的PHP脚本可以改变句子的顺序吗?
你可以像这样完成它.在句子的末尾分解一个字符串,例如句号.使用该shuffle
功能对阵列进行随机播放.然后内爆字符串,添加完整的停止.
输出将是这样的:
Hello, this is one sentence. This is a fifth. This is a forth. This is a second.. THis is a third
$sentences = 'Hello, this is one sentence. This is a second. THis is a third. This is a forth. This is a fifth.'; $sentencesArray = explode('.', $sentences); array_filter($sentencesArray); shuffle($sentencesArray); $sentences = implode('.', $sentencesArray); var_dump($sentences);