我有一些由一些列組成的表格,其中一個是document_content
列(帶有期刊內容)和文本類型。我想分析內容以獲得摘要。我認爲摘要是abstract
本身和introduction
之間的內容。從表格的文件內容中獲取摘要
這裏是我的代碼:
$id = array('1','2','3','4','5','6','7','8','9');
$sql = mysql_query('SELECT document_id, document_content FROM tbdocument WHERE document_id IN (' . implode(",", $id) . ')') or die(mysql_error());
while ($row = mysql_fetch_array($sql)) {
$files[$row['document_id']] = $row['document_content'];
}
foreach ($files as $doc_id => $file){
if (strpos($file, 'ABSTRACT')){
if (strpos ($file, 'INTRODUCTION')){
$between = substr($file, (strpos($file, 'ABSTRACT')+8), (strpos($file, 'INTRODUCTION')-13) - strpos($file, 'ABSTRACT'));
if (strpos($file, 'Introduction')){
$between = substr($file, (strpos($file, 'ABSTRACT')+8), (strpos($file, 'Introduction')-13) - strpos($file, 'ABSTRACT'));
}
}
else {
if (strpos($file, 'Abstract')){
if (strpos ($file, 'Introduction')){
$between = substr($file, (strpos($file, 'Abstract')+8), (strpos($file, 'Introduction')-13) - strpos($file, 'Abstract'));
}
if (strpos($file, 'INTRODUCTION')){
$between = substr($file, (strpos($file, 'Abstract')+8), (strpos($file, 'INTRODUCTION')-13) - strpos($file, 'Abstract'));
}
}
}
$q = mysql_query("INSERT INTO tb_metadata SET document_id = {$doc_id}, metadata_abstract = '{$between}'") or die(mysql_error());
}
,但它給了我空白的結果。我的代碼有什麼問題?非常感謝你:)
首先,您可以通過使用'stripos'(不區分大小寫)而不是'strpos'來顯着簡化您的邏輯:http://us2.php.net/stripos – 2012-08-07 21:40:07
接下來,您可以考慮一個正則表達式解決方案,它可以無論是SQL還是PHP。 – 2012-08-07 21:41:34
@ctrahey哦,謝謝!我會嘗試使用'stripos' – 2012-08-07 21:49:41