Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6735719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:02:45+00:00 2026-05-26T11:02:45+00:00

This is probably real simple, but I don’t know best way to do this.

  • 0

This is probably real simple, but I don’t know best way to do this. I am pulling data from a mysqli database with php to create an XML document. My code below works but data in the Title field is all caps. I need just the first character capitalized, the rest lowercase. I know I need the ucwords function, but no dice yet. The Title field has more than one word in all caps.

I need the data formatted by ucwords before it goes into the XML area. I prefer to do this in the php instead of updating the data in the db. Thanks for the help!

<?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);
 }
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:02:46+00:00Added an answer on May 26, 2026 at 11:02 am

    The relevant section in http://php.net/manual/en/function.ucwords.php

    <?php
    $foo = 'hello world!';
    $foo = ucwords($foo);             // Hello World!
    
    $bar = 'HELLO WORLD!';
    $bar = ucwords($bar);             // HELLO WORLD!
    $bar = ucwords(strtolower($bar)); // Hello World!
    ?>
    

    For your query, I’d replace:

    // 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);    
    

    With:

    $results = mysqli_query("SELECT * FROM table");
    

    Then change your while loop to:

    foreach($results as $row) {
        $xw->startElement('item');
        $xw->writeElement('Name', ucwords(strtolower($row['name']));
        $xw->writeElement('Title', ucwords(strtolower($row['title']));
        $xw->endElement();
    }
    

    Obviously you need to tinker with this since I don’t know your database schema.

    The main reason for changing the mysqli stuff is that you aren’t guaranteed to have the same ordering of the database columns if you make schema changes to the database in the future.

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this probably really simple but Im not sure what im doing wrong...
This is probably a real simple question but I'm looking for the most memory
This probably has a simple answer, but I must not have had enough coffee
Ok, this probably has a really simple answer, but I've never tried to do
This is probably insultingly simple and worthy of a Nelson Muntz laugh, but I'm
This is probably a real simple one. I wished to create some code inside
This probably sounds really stupid but I have noo idea how to implement jquery's
This probably sounds like a terrible idea at first glance, but here is my
I am using ASP.Net MVC but this probably applies to all MVC patterns in
Okay, so this probably sounds terribly nefarious, but I need such capabilities for my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.