0

次の構文でメモ帳++で作成したヘルプファイルがあります

//Filename:PHP_Help.html

<!-- Heading of the Issue/Solution

// it may contain PHP Code or Mysql Queries or General Description
<?php

    // Code that fixed the issue/ Solution to a problem
?>

Some general Description
-->

Notepad ++で「ALT + 0」を押すと、上記の形式を使用したためです

として表示されます

<!-- Heading of issue 1
<!-- Heading of issue 2

見出しを読んで問題の解決策を見つけるのに役立ちます。しかし、ヘルプ ファイルのサイズが大きくなり、何百もの問題が含まれています。

だから私はファイルをデータベースにロードし、PHPを使用して問題/解決策を検索しようとしています

私のデータベーススキーマは次のようになります

Create table issues
(
 id int auto_increment primary key,
 header nvarchar(100),
 content text
);

私の質問は、特定のファイルをデータベースにロードするにはどうすればよいですか?

4

1 に答える 1

0
// Read the file into a php variable:
$filecontents = file_get_contents ("PHP_Help.html");

// explode the string into individual records:
$records = explode ( "<!--" , $filecontents );

// work through the array of records:
foreach($records as $record) {
    // find your first linefeed
    $headingend = strpos($record, chr(13) );
    // get the heading
    $heading = substr($record, 0, $headingend);
    // and the content
    $content = substr($record, $headingend);
    // write to the database...
}
于 2012-05-08T05:44:16.507 に答える