国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Yang baru. Saya mahu menggunakan XML untuk mencipta fungsi notepad mudah, jadi saya menemui kod. Selepas berjalan, anda boleh menambahnya, tetapi anda tidak boleh memadamkannya.
萌新
萌新 2023-10-27 09:05:08
0
0
677
<?php  
// 定義XML文件路徑和記事本數(shù)據(jù)表名  
$xmlFilePath = 'data.xml';  
$tableName = 'notes';  
  
// 創(chuàng)建數(shù)據(jù)庫連接(XML文件)  
$xml = simplexml_load_file($xmlFilePath);  
  
// 添加記事本記錄  
if (isset($_POST['submit'])) {  
    $title = $_POST['title'];  
    $content = $_POST['content'];  
  
    // 在XML文件中創(chuàng)建新的記事本記錄  
    $newNote = $xml->addChild('note');  
    $newNote->addChild('title', $title);  
    $newNote->addChild('content', $content);  
  
    // 保存XML文件  
    $xml->asXML($xmlFilePath);  
}  
  
// 刪除記事本記錄  
if (isset($_GET['delete'])) {  
    $noteId = $_GET['delete'];  
  
    // 在XML文件中刪除指定記事本記錄  
    foreach ($xml->xpath("//note[@id='$noteId']") as $note) {  
        $noteParent = $note->xpath('..');  
        unset($noteParent[0][$note->getName()]);  
    }  
  
    // 保存XML文件  
    $xml->asXML($xmlFilePath);  
}  
 
/*if (isset($_GET['delete'])) {    
    $noteId = $_GET['delete'];    
    
    $notes = $xml->xpath("//note[@id='$noteId']");    
    if (isset($notes[0])) {    
        unset($notes[0]);    
    }    
    
    $xml->asXML($xmlFilePath);    
}
*/
  
// 更新記事本記錄  
if (isset($_POST['update'])) {  
    $noteId = $_POST['id'];  
    $title = $_POST['title'];  
    $content = $_POST['content'];  
  
    // 在XML文件中更新指定記事本記錄  
    foreach ($xml->xpath("//note[@id='$noteId']") as $note) {  
        $note->title = $title;  
        $note->content = $content;  
    }  
  
    // 保存XML文件  
    $xml->asXML($xmlFilePath);  
}  
  
// 查詢記事本記錄  
$notes = $xml->xpath("//note");  
?>  
<!DOCTYPE html>  
<html>  
<head>  
    <title>網(wǎng)絡(luò)記事本</title>  
</head>  
<body>  
    <h1>網(wǎng)絡(luò)記事本</h1>  
  
    <!-- 添加記事本記錄 -->  
    <form method="post" action="">  
        <label for="title">標題:</label>  
        <input type="text" name="title" id="title" required><br><br>  
        <label for="content">內(nèi)容:</label><br>  
        <textarea name="content" id="content" rows="4" cols="50" required></textarea><br><br>  
        <input type="submit" name="submit" value="添加記錄">  
    </form>  
  
    <!-- 顯示記事本記錄 -->  
    <h2>記事本記錄</h2>  
    <ul>  
        <?php foreach ($notes as $note): ?>  
            <li id="note_<?php echo $note->id; ?>">  
                標題: <?php echo $note->title; ?>, 內(nèi)容: <?php echo $note->content; ?>  
                <a href="?delete=<?php echo $note->id; ?>">刪除</a>  
            </li>  
        <?php endforeach; ?>  
    </ul>  
</body>  
</html>

Comel baru. Saya mahu menggunakan XML untuk mencipta fungsi notepad mudah, jadi saya menemui kod. Selepas berjalan, anda boleh menambahnya, tetapi anda tidak boleh memadamkannya. Tolong saya, cikgu. Terima kasih~QQ截圖20231027090436.png

萌新
萌新

membalas semua(0)
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan