1

Possible Duplicate:
Browser displays � instead of ´

On my website, when I copy a block of text from someone else's text document that use different characters, such as the longer dash, and the other kind of quotes apart from '' "" it returns the html junk. such as:

9 am – 4 pm

looks like:

9 am � 4 pm

and

as ‘secrets’, ‘remembering/keeping,’, narratives, and ‘surprises.’

looks like:

as �secrets�, �remembering/keeping,�, narratives, and �surprises.�

my php for inserting the data simply is:

strip_tags($_POST['details']);

and my php for outputting it on the page as html is:

stripslashes(linkify(nl2br(htmlentities($row['body']))));

what am I doing wrong?

Community
  • 1
  • 1
Dylan Cross
  • 5,918
  • 22
  • 77
  • 118
  • See my answer to this question: http://stackoverflow.com/questions/12220453/mysql-insert-column-half-inserted/12220491#12220491 – Jeremy Harris Oct 16 '12 at 17:43
  • Run the string through a regular expression that removes all non-alphanumeric characters and symbols. EDIT: That is, if you want to remove the 'corrupt' characters. – Scott Oct 16 '12 at 17:44

3 Answers3

0

Try use this header in PHP, before to output data:

if(!headers_sent()) header('Content-type: text/html; charset=utf-8');

And:

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

In HTML document. Also, check in MySQL to see how date are registered.

CoursesWeb
  • 4,179
  • 3
  • 21
  • 27
0

You have utf characters in your html, there are a variety of things you can do, the best would be to adjust the headers at the top of your php page .... just as coursesweb mentioned above.

If you don't know about headers, you have to send them before any thing is sent back to your browser, so it should really be towards the top, if not the first line.

Landon
  • 4,088
  • 3
  • 28
  • 42
  • See my comments to CoursesWeb – Dylan Cross Oct 16 '12 at 20:18
  • The meta tag you are referring to is actually not really used much any more. Your server is automatically sending a header for `Content-type` which supersedes what you put in your meta tag. You can remove that tag, or change it, and it shouldn't have much of a difference. You really need to send the correct charset as **part of the http headers**. You can adjust that in your php.ini file (I think), or an easier way is to just start your php script with that header() command. – Landon Oct 16 '12 at 21:10
  • Well no matter what I've tried, which I've tried about everything I can find on the internet, it doesn't even begin to fix the problem :\ – Dylan Cross Oct 16 '12 at 22:43
  • you put the php header in there? this is presuming your content is utf-8, do you have any idea what it is? – Landon Oct 16 '12 at 23:17
0

If the charset stuff isn't helping you, I have a hackish solution. If it's just static text you're worried about (ie nothing in a database), this might work. Select your text, copy it and paste it in a plain text editor, if you're on windows, notepad (not wordpad) might do the trick. Copy what you just pasted and then paste that in your php/html file. Give that a try and that might replace the "bad" characters with more standard ones.

Landon
  • 4,088
  • 3
  • 28
  • 42
  • This text gets inputted to the database this way, this problem occurs when coping text from a document (such as pages, or word), and then save it, So it seems like it's something to do with inputting it to the database. – Dylan Cross Oct 16 '12 at 23:59
  • maybe it's a mysql thing then? what is your charset there? i know latin1 is the default on most installations. I went through this a while ago, I changed all tables to utf-8, and outputted the header mentioned above in php and I can show everything (accents, chinese, etc). – Landon Oct 17 '12 at 01:00
  • Maybe do some queries in your mysql shell to make sure that the data isn't broken there. if it is stored in a broken format, then there's nothing you can do in php/html world to fix it anyway. – Landon Oct 17 '12 at 01:01
  • Well, I changed my database to utf-8 but that didn't fix it. – Dylan Cross Oct 17 '12 at 01:20