本文整理汇总了PHP中DOMDocument::Save方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMDocument::Save方法的具体用法?PHP DOMDocument::Save怎么用?PHP DOMDocument::Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::Save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: DOMDocument
<?php
include '../../config/config.php';
$xml = new DOMDocument("1.0", "utf-8");
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->Load('../../data/tags.xml');
// $sql = "SELECT Auto_increment FROM information_schema.tables WHERE table_name='tbltag'";
// $query = mysqli_query($conn, $sql);
// $result = mysqli_fetch_row($query);
$name = $_POST['tag_name'];
$stmt = $conn->prepare("INSERT INTO tbltag (tag_name) VALUES(?)");
$stmt->bind_param("s", $name);
$stmt->execute();
$id = mysqli_insert_id($conn);
$new_tag = $xml->createElement("tag");
$new_tag->appendChild($xml->createElement('id', $id));
$new_tag->appendChild($xml->createElement('name', $name));
$xml->getElementsByTagName('tags')->item(0)->appendChild($new_tag);
$xml->Save('../../data/tags.xml');
header('Location: ../tag_list.php');
示例2: DOMDocument
$category_id = $_POST['category_id'];
$category_name = $_POST['category_name'];
$category_details = $_POST['category_details'];
// update record from database
$sql = "UPDATE tblcategory set category_name ='" . $category_name . "',category_details ='" . $category_details . "' WHERE category_id = '" . $category_id . "' LIMIT 1";
$conn->query($sql);
if ($conn->query($sql)) {
$xml = new DOMDocument("1.0", "utf-8");
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->Load('../../data/category.xml');
$root = $xml->getElementsByTagName('categories')->item(0);
$categories = $root->getElementsByTagName('category');
foreach ($categories as $category) {
if ($category->getElementsByTagName('id')->item(0)->nodeValue == $category_id) {
$category->getElementsByTagName('name')->item(0)->nodeValue = $category_name;
$category->getElementsByTagName('details')->item(0)->nodeValue = $category_details;
}
}
$xml->Save('../../data/category.xml');
$return = array("status" => "200", "message" => "Success");
echo json_encode($return);
} else {
echo "ERROR: could not prepare SQL statement.";
}
$conn->close();
// redirect user after delete is successful
// header("Location: ../category_list.php");
} else {
// header("Location: ../category_list.php");
}
示例3: tblproduct
$stmt = $conn->prepare("INSERT INTO tblproduct (product_name,category_id,description,quantity,price,product_image) VALUES(?,?,?,?,?,?)");
$stmt->bind_param("ssssss", $name, $category, $description, $quantity, $price, $product_image);
$stmt->execute();
$id = mysqli_insert_id($conn);
include '../../config/config.php';
$tag_names = str_replace(array('[', ']'), '', implode("','", $tags_array_string));
$sql = "SELECT tag_id FROM tbltag WHERE tag_name IN ({$tag_names})";
$query = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($query)) {
$tags_array_id[] = $row['tag_id'];
}
$tags_sql = '';
foreach ($tags_array_id as &$tag_id) {
$tags_sql .= "INSERT INTO tblproduct_tag (product_id, tag_id, category_id) \n\t \t\t\t\tVALUES ('" . $id . "','" . $tag_id . "','" . $category . "');";
//SAVE EACH ITEMS IN THE PRODUCT TAG TABLE
}
$conn->multi_query($tags_sql);
$conn->close();
//====================== XML INTEGRATION
$new_product = $xml->createElement("product");
$new_product->appendChild($xml->createElement('id', $id));
$new_product->appendChild($xml->createElement('name', $name));
$new_product->appendChild($xml->createElement('description', $description));
$new_product->appendChild($xml->createElement('quantity', $quantity));
$new_product->appendChild($xml->createElement('price', $price));
$new_product->appendChild($xml->createElement('image', $product_image));
$new_product->appendChild($xml->createElement('category', $category));
$xml->getElementsByTagName('products')->item(0)->appendChild($new_product);
$xml->Save('../../data/products.xml');
header('Location: ../products_list.php');
$return = array("status" => "200", "message" => "Success");
示例4: DOMDocument
// CREATE AN XML DATA
$xml = new DOMDocument("1.0", "utf-8");
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->Load('data/users.xml');
$new_user = $xml->createElement("user");
$new_user->appendChild($xml->createElement('id', $id));
$new_user->appendChild($xml->createElement('firstname', $firstName));
$new_user->appendChild($xml->createElement('middlename', $middleName));
$new_user->appendChild($xml->createElement('lastname', $lastName));
$new_user->appendChild($xml->createElement('contact', $contact));
$new_user->appendChild($xml->createElement('address', $address));
$new_user->appendChild($xml->createElement('email', $email1));
$new_user->appendChild($xml->createElement('birthdate', $birthdate));
$xml->getElementsByTagName('users')->item(0)->appendChild($new_user);
$xml->Save('data/users.xml');
// =============================
$registerMessage = "Your have successfully created a new account.<br><a href='index.php'>Log In </a>";
$_SESSION['registerMessage'] = $registerMessage;
}
// header('Location: /index.php/#login');
}
$_SESSION['captcha'] = rand(1000, 9999);
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body class="register-wrapper">
示例5: array
$id = $_GET['id'];
// delete record from database
if ($stmt = $conn->prepare("DELETE FROM tbluser WHERE userID = ? LIMIT 1")) {
$stmt->bind_param("s", $id);
$stmt->execute();
$stmt->close();
$return = array("status" => "200", "message" => "Success");
echo json_encode($return);
// delete to XML FILE
$xml = new DOMDocument("1.0", "utf-8");
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->Load('../../data/users.xml');
$root = $xml->getElementsByTagName('users')->item(0);
$users = $root->getElementsByTagName('user');
foreach ($users as $user) {
$current_id = $user->getElementsByTagName('id')->item(0)->nodeValue;
if ($current_id == $id) {
$root->removeChild($user);
}
}
$xml->Save('../../data/users.xml');
} else {
echo "ERROR: could not prepare SQL statement.";
}
$conn->close();
// redirect user after delete is successful
// header("Location: ../user_list.php");
} else {
// header("Location: ../user_list.php");
}