andrew
andrew

Reputation: 9593

jQuery load character encoding issue

Please note, I have read the similar questions and the suggested answer frequently popping up:

<?php
 header("Content-Type: text/html; charset=utf-8");
 ?>

Did not solve the issue.

Here's the header of my outer page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        ...

Here is a sample of inner.php

 <p>£</p>
 <p><?php echo $employee->salary; ?></p> <!-- employee->salary = £30,000 (from db) -->

I'm loading with jquery:

 $('#salary').load('inner.php')

On the output of the outer page I'm seeing:

£
�30,000

inner.php when viewed in the console looks like:

£
£30,000

I need the output on the outer page to appear as £30,000 and I'm unable to figure out what I'm doing wrong

Upvotes: 0

Views: 1695

Answers (1)

meatFeed
meatFeed

Reputation: 124

Play around with utf8_decode or utf8_encode and wrap it around your DB Output:

<p><?php echo utf8_encode($employee->salary); ?></p>

Maybe your DB isn't delivering UTF-8 strings.

If you not have any reason to use the ISO-8859-1 charset on your site other than external text of which you have no control over (and is in fact encoded iso-8859-1), use UTF-8 in

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Upvotes: 1

Related Questions