我有一些句子。我必须选择包含超过 6 个单词的句子。然后它们将被插入到数据库中。
<?php
require_once 'conf/conf.php';
$text = " Poetry. Do you read poetry while flying? Many people find it relaxing to read on long flights. Poetry can be divided into several genres, or categories. ";
$sentences = explode(".", $text);
foreach ($sentences as $sentence) {
if (count(preg_split('/\s+/', $sentence)) > 6) {
$save = $sentence. ".";
$sql = mysql_query("INSERT INTO tb_name VALUES('','$save')");
}
}
?>
结果只有插入数据库的第二句话 => '你在飞行时读诗吗?许多人发现在长途飞行中阅读很放松。” 而第三句也应插入。请帮助我,谢谢:)