我有一個由一些句子的文本。我必須解析每個句子中由點和數字分隔的句子。包含5個以上單詞的句子將被插入到數據庫中。這裏是我的代碼:我需要從一些文本文件某些規格的句子,然後將它們存儲到數據庫
<?php
require_once 'conf/conf.php';// connect to database
function saveContent ($text) {
//I have to get every sentence without lose the dot
$text1 = str_replace('.', ".dot", $text);
$text2 = explode ('dot',$text1);
//Text that contain ' cannot be inserted to database, so i need to remove it
$text3 = str_replace("'", "", $text2);
//Selecting the sentence that only consist of more than words
for ($i=0;$i<count($text3);$i++){
if(count(explode(" ", $text3[$i]))>5){
$save = $text3[$i];
$q0 = mysql_query("INSERT INTO tbdocument VALUES('','$files','".$save."','','','') ");
}
}
}
$text= "I have some text files in my folder. I get them from extraction process of pdf journals files into txt files. here's my code";
$a = saveContent($text);
?>
結果是隻能插入數據庫的1句(第一句)。 我需要你的幫助,非常感謝你:)
您_can_插入'''到數據庫中,如果正確地轉義。 '$ text2 = mysql_real_escape_string($ text2);' –
不要使用'mysql_ *',請切換到PDO或'mysqli' –
'mysql_real_escape_string',因爲'mysql_escape_string'不夠真實:D – Louis