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 7547243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:24:10+00:00 2026-05-30T09:24:10+00:00

I have a Function (within the class Database) function locTo (){//return the location of

  • 0

I have a Function (within the class Database)

            function locTo (){//return the location of the to currency
                $con = dbconnect(); //instantiate db connection
                $locationTo= mysql_query ("SELECT location  FROM Sheet1 where currency_code = '$this->to'", $con);
                $lol = mysql_fetch_array($locationTo);
                return $lol['location'];
                mysql_close();
                  }

when I call the function

$foo = new Database($from,$to);
$hey = $foo->LocTo();
echo $hey;

or

 $foo = new Database($from,$to);
 echo $foo->LocTo();

It out puts correctly.

Im trying to put into XML and im getting an encoding error.

This is my XML

echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<conv>';
echo'<at>'.$timefrom.'</at>';
echo'<rate>'.$rate.'</rate>';
echo'<from>';
echo'<code>'.$from.'</code>';
echo'<curr>'.$currencyFrom.'</curr>';
echo'<loc>'.$locFrom.'</loc>';
echo'<amnt>'.$amount.'</amnt>';
echo'</from>';
echo'<to>';
echo'<code>'.$to.'</code>';
echo'<curr>'.$currencyTo.'</curr>';
echo'<loc>'.$locTo.'</loc>';
echo'<amnt>'.$convertedAmount.'</amnt>';
echo'</to>';
echo'</conv>';

Does anyone know why I am getting an encoding error? I have checked the source code and it gets as far as the location.

here is an example of the location out put.

AED to GBP

 United Arab Emirates
 United Kingdom, Crown Dependencies (the  Isle of Man and the Channel Islands), certain      British Overseas Territories ( South Georgia and the South Sandwich Islands,  British      Antarctic Territory and  British Indian Ocean Territory)
  • 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-30T09:24:12+00:00Added an answer on May 30, 2026 at 9:24 am

    I recommend switching to (for example) DOM so your code would look like this:

    <?php
    
    $dom = new DOMDocument('1.0', 'UTF-8');
    $dom->formatOutput = true; // Just for presentation, don't use this in real app
    $main = $dom->createElement( 'conv');
    $dom->appendChild( $main);
    
    // Generic attributes
    $main->appendChild( $dom->createElement( 'at', $timefrom));
    $main->appendChild( $dom->createElement( 'rate', $rate));
    
    // Fill form
    $from = $dom->createElement( 'from');
    $from->appendChild( $dom->createElement( 'code', $row['from']));
    $from->appendChild( $dom->createElement( 'curr', $currencyFrom));
    $from->appendChild( $dom->createElement( 'loc', 'time'));
    $from->appendChild( $dom->createElement( 'amnt', 'time'));
    $main->appendChild( $from);
    
    // Fill to 
    $to = $dom->createElement( 'to');
    $to->appendChild( $dom->createElement( 'at', 'time'));
    $to->appendChild( $dom->createElement( 'code', 'time'));
    $to->appendChild( $dom->createElement( 'curr', 'time'));
    $to->appendChild( $dom->createElement( 'loc', 'time'));
    $to->appendChild( $dom->createElement( 'amnt', '<img />'));
    $main->appendChild( $to);
    
    echo $dom->saveXML();
    

    This should make your XML always valid. The result would look like (filled just with string 'time'):

    <?xml version="1.0" encoding="UTF-8"?>
    <conv>
      <at>time</at>
      <rate>time</rate>
      <from>
        <code>time</code>
        <curr>time</curr>
        <loc>time</loc>
        <amnt>time</amnt>
      </from>
      <to>
        <at>time</at>
        <code>time</code>
        <curr>time</curr>
        <loc>time</loc>
        <amnt>&lt;img /&gt;</amnt>
      </to>
    </conv>
    

    Take a look at last <amnt /> it’s correctly “xml escaped”, you don’t have to worry about it anymore, but be careful when using DOMELement->noveValue = html AFAIK this doesn’t escape your values.

    And of course don’t forget to set correct header(), use (before sending any output):

    header('Content-Type: text/xml, charset=utf-8');
    

    Also take a look at 14.17 Content-Type and MIME types on wiki.

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

Sidebar

Related Questions

I have a class to connect to my database, strip stuff and return things
I have two classes, Database and User. In the Database class I have function
I have this code here within a class: function getRolePerms($role) { if (is_array($role)) {
I have written a database class but can't access the method from within: class
The problem seems very strange. I have a AJAX helper function within a same
I have the following function which works very well within a $(document).ready(function(){ $('.threadWrapper >
I have to allocate a struct from within another function, obviously using pointers. I've
I have the following within an XHTML document: <script type=text/javascript id=JSBALLOONS> function() { this.init
i have function public Menu Details(int? id) { return _dataContext.Menu.Include(ChildMenu).FirstOrDefault(m => m.MenuId == id);
I am trying to get a users ID from a database within a class,

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.