我的表格由一些列组成,其中之一是document_content
文本类型的列(期刊内容)。我想解析内容以获取摘要。我假设 abstract 是单词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());
}
但它给了我空白的结果。我的代码有什么问题?非常感谢您 :)