1

Say I have text and I have several of the same umlaut e.g. the ü umlaut which is ü in html. I am posting text into a form to an article using php fopen fwrite fclose etc.

I want to be able to copy and paste text that contains umlauts into my form without having to replace each umlaut ü, with the html ü. Is there a function in Javascript or php, or meta tag that can automatically change lets say all the umlauts ü into ü so that they display correctly? Right now I'm getting the diamond question mark character replacement for each umlaut.

Rizier123
  • 58,877
  • 16
  • 101
  • 156
  • 5
    How about using UTF-8 encoding throughout your entire software stack? That way you won't need any HTML entities. – Philipp Nov 18 '14 at 22:09
  • `str_replace("ü", "ü", $string)` ? Or just simple use UTF-8 encoding! – Rizier123 Nov 18 '14 at 22:09
  • I've tried UTF-8 encoding, I don't believe it works with umlauts, I'll try the function thanks! –  Nov 18 '14 at 22:12
  • utf-8 works with umlauts. most likely there is some component in your stack that just can't handle utf8. – lordvlad Nov 18 '14 at 22:27
  • possible duplicate of [How to convert some multibyte characters into its numeric html entity using PHP?](http://stackoverflow.com/questions/5123638/how-to-convert-some-multibyte-characters-into-its-numeric-html-entity-using-php) – Conspicuous Compiler Nov 18 '14 at 22:29
  • Found the problem UTF-8 does work! Thanks everybody! –  Nov 18 '14 at 22:38

2 Answers2

0

Is there a function in Javascript or php, or meta tag that can automatically change lets say all the umlauts ü into ü

Yes, the htmlentities function does exactly this. Btw, it makes no sense to attempt such transformations at the client side, so no JS.

so that they display correctly?

If that is the problem, you should consider using a consistent encoding for (uploading), receiving, storing, and sending the texts.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
0

If you can't or don't want to switch your stack to UTF8 encoding, there is a native PHP function (htmlentities, described here), but sadly none for JS. But you can make use of the htmlspecialchars function posted here.

By default, modern browsers auto-detect the websites character encoding, but you can help them out by setting a meta tag. This answer has some more tips on how to set up your stack for utf8.

Community
  • 1
  • 1
lordvlad
  • 5,200
  • 1
  • 24
  • 44