Это, наверное, очень просто, но я не знаю лучшего способа сделать это.Я извлекаю данные из базы данных mysqli с помощью php для создания XML-документа.Мой код ниже работает, но данные в поле заголовка все заглавные.Мне нужен только первый символ с заглавной буквы, остальные строчные.Я знаю, что мне нужна функция ucwords, но пока нет кубиков.Поле Заголовок содержит более одного слова во всех заглавных буквах.
Мне нужны данные, отформатированные с помощью ucwords, прежде чем они попадут в область XML.Я предпочитаю делать это в php вместо обновления данных в БД.Спасибо за помощь!
<?php
// Connect to the database
global $link;
$link = mysqli_connect("localhost", "root", "pass", "database");
// Verify the connection worked
if (!$link) {
printf("Connection to database failed: %s\n", mysqli_connect_error());
exit();
}
// Prepare the database query
$stmt = mysqli_prepare($link, "SELECT * FROM table");
// Run the database query
mysqli_stmt_execute($stmt);
// Bind the result columns to PHP variables
mysqli_stmt_bind_result($stmt, $Name, $Title);
// Create a new XML document in memory
$xw = new xmlWriter();
$xw->openURI('php://output');
$xw->openMemory();
$xw->startDocument('1.0');
// Start the outer data container
$xw->StartElement('rss');
$xw->WriteAttribute('version', '2.0');
// Fetch values
while (mysqli_stmt_fetch($stmt)) {
{
$xw->startElement('item');
// Write out the elements
$xw->writeElement('Name', $Name);
$xw->writeElement('Title', $Title);
$xw->endElement();
}
// End container
$xw->endElement();
// End the document
$xw->endDocument();
//header('Content-Type: text/xml');
print $xw->outputMemory(true);
// Close the database statement
mysqli_stmt_close($stmt);
// Close the database connection
mysqli_close($link);
}
?>