Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


Results 1 to 2 of 2

Thread: php/xml/encoding="utf-8"

  1. #1


    hello All!!!
    first of all happy new year!!

    I'm doing some experiencies in producing trough php a xml file from a wordpress database to read from a flash website

    I take this tuto from Jubba!!

    my first problem encoding utf=8 its not working
    this is my php code:
    PHP Code:

    ("Content-type: text/xml; charset=utf-8");

    $host 'localhost';
    $user 'myuser';
    $pass '*****';
    $database 'mydb';

    $linkID mysql_connect($host$user$pass) or die("Could not connect to host.");
    mysql_select_db($database$linkID) or die("Could not find database.");

    $query "SELECT * FROM wp_posts ORDER BY post_date DESC";
    $resultID mysql_query($query$linkID) or die("Data not found.");

    $xml_output "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
    $xml_output .= "<entries>\n";
    $x $x mysql_num_rows($resultID) ; $x++){
    $row mysql_fetch_assoc($resultID);
    $xml_output .= "\t<entry>\n";
    $xml_output .= "\t<date>" $row['post_date'] . "</date>\n";
    // Escaping illegal characters
    $xml_output .= "\t<text>" $row['post_content'] . "</text>\n";
    $xml_output .= "\t</entry>\n";
    $xml_output .= "</entries>";


    you can check this in real time here

    if you check the page source in your browser so will see <?xml version="1.0" encoding="utf-8"?>

    but the special char are not translated.

    If anybody can give me a clue as you see this is very strange, for me its a php thing!!

    many thnks
    Last edited by voxoff; January 4th, 2008 at 12:00 PM.

  2. #2
    i find the solution for my issue it seams that this encoding was making

    PHP Code:
    $xml_output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
    trouble with the encoding declaration in the header

    PHP Code:
    header("Content-type: text/xml; charset=utf-8"); 
    so if you only declare the charset in the header there is no problem!!

    a get a new php code that produces the xml file if you are interested

    PHP Code:

    ("Content-type: text/xml; charset=utf-8");

    $host '*';
    $user '*';
    $pass '*';
    $database '*';

    $linkID mysql_connect($host$user$pass) or die("Could not connect to host.");
    mysql_select_db($database$linkID) or die("Could not find database.");

    $query "SELECT * FROM wp_posts ORDER BY post_title DESC";
    $resultID mysql_query($query$linkID) or die("Data not found.");
    $num mysql_num_rows($resultID);

    if (
    $num != 0) {
    $_xml ="<?xml version=\"1.0\" ?>\r\n";
    $_xml .="<site>\r\n";
     while (
    $row mysql_fetch_array($resultID)) {
     if (
    $row["post_title"]) {
    $_xml .="\t<tt>" $row["post_title"] . "</tt>\n";
     } else {
    $_xml .="\t<page title=\"Nothing Returned\">\r\n";
    $_xml .="\t\t<file>none</file>\r\n";
    $_xml .="\t</page>\r\n";
     } }
    $_xml .="</site>";
    "<a href=\"results.xml\">View the XML.</a>";
     } else {
    "No Records found";

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About kirupa.com Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012