jeevan
jeevan

Reputation: 175

’ is being displayed instead of -

’ is being displayed instead of - in php page

I tried using different encoding types like:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>

and

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

but result is the same. What could be the problem?

Input

<strong style="color:#A8A8A8;">1</strong> – Lorem Ipsum.

Result

1 – Lorem Ipsum.

Upvotes: 6

Views: 17019

Answers (6)

Learner
Learner

Reputation: 1

Add the following header tag:

<meta charset="UTF-8">

Upvotes: -1

user3711421
user3711421

Reputation: 1808

Had the same problem when creating a file from javacode and setting the encoding to UTF-16 did the trick.

Upvotes: -1

ANisus
ANisus

Reputation: 77965

Your document is most likely encoded in UTF-8 since – is the iso-8859-1 presentation of the UTF-8 encoded character .

What you need is the meta-tag you describe:

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

Since it isn't working, the tag might to be ignored. Suggestion is to use the browser and check what encoding it tries to use (Tools - Encoding in Chrome).

  • If the browser uses UTF-8, you have double-encoded the characters. Check your code if so that you don't have an excessive utf8_encode(...)
  • If the browser uses Latin1 (iso-8859-1) your tag is ignored or overridden by the HTTP header. Try to validate your HTML with an online validator. Check the sent header information with your browser's development tool to make sure iso-8859-1 is not set as encoding.

Upvotes: 1

Matteo Italia
Matteo Italia

Reputation: 126787

The fact that the meta tag doesn't change the output is a strong indicator that there's something overriding it; probably it's the charset specified in the HTTP header (which has precedence over the meta tag), are you sure you're not setting it there?

Upvotes: 2

Tony Stark
Tony Stark

Reputation: 8084

Make sure your html header specifies utf8

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

That usually does the trick for me (obviously if the content IS utf8).

You don't need to convert to html entities if you set the content-type.


check http://php.net/manual/en/function.mb-convert-encoding.php

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

may be this will help you.

Upvotes: 5

Daan
Daan

Reputation: 191

It looks like your source data is converted from one to another encoding along the way. Try to make sure ALL steps have the same encoding.

  1. Is your (MySQL?) data stored as UTF8?
  2. Is your .php file saved as UTF8?

Conversion errors like this usually pop up when handling UTF8 data as ISO-8859-1 data. (multibyte vs singlebyte? not sure).

Upvotes: 2

Related Questions