", $str); $str = htmlspecialchars($str, ENT_QUOTES); $str = mb_convert_encoding($str, "HTML-ENTITIES", "UTF-8"); $str = htmlentities($str); return $str; }; $hostname = 'localhost'; // Replace with your database hostname $username = 'chezjeff'; // Replace with your database username $password = 'thwaouthbo'; // Replace with your database password $database = 'chezjeff01'; // Replace with your database name // Create a new mysqli instance $mysqli = new mysqli($hostname, $username, $password, $database); $xml = simplexml_load_file('logan2007-comment.xml'); // Iterate over each "item" node foreach ($xml->item as $item) { // Access the "id" and "body" elements $id = (string)$item->id; $body = (string)$item->body; $name = (string)$item->name; $link = (string)$item->link; $date = (string)$item->date; // Display the id and body values #echo "ID: $id\n"; #echo "Body: $body\n"; #echo "\n"; $query = "insert into `comment12` values ('" . $name ."', '" . $link . "', '" . $date . "', '". encodeEntities($body) ."', '". $id. "');\n"; echo $query; mysqli_query($mysqli, $query); }; ?>