2

I have been searching around on the internet and have found lots of discussions about regex for stripping out or fixing special characters coming through in HTML, but I am looking for a different solution.

I have some text coming through that looks like this: 12DR - Constant™ Cloth.

That texts comes through and when I append it to a div on my page, it looks like this: 12DR - Constantâ„¢ Cloth.

I don't know all of the special characters coming through. Is there some function that I am missing that cleans up the text to show in HTML properly without me having to manually write regex for each possible character?

HighHopes
  • 2,014
  • 3
  • 23
  • 33

8 Answers8

1

I believe this http://www.web2generators.com/html-based-tools/online-html-entities-encoder-and-decoder is what you are looking for. This site replaces the special characters in a given text with their corresponding html codes for you.

Take whatever text you need converted and paste it into the text box. Then press encode and you can do whatever you need with it!

Luke
  • 838
  • 7
  • 17
0

Most browsers support HTML codes for special characters. The code for the trademark symbol if &#8482.

Sam Siegel
  • 21
  • 3
0

It looks like a character encoding issue. To solve this, you need to know what is the input encoding format, and the one used in your website.

Blind advice : your website and database should both be encoded in UTF-8, and if your text input use a different one, convert it when you acquire it. That will solve all your encoding problems forever.

technico
  • 1,192
  • 1
  • 12
  • 22
0

Try something like this.

Make a span with a class of TM

  <span class='tm'></span>

And then in the css file you will need to use a :before or :after tag like this

.tm:after
{
    content:'\2122';
    font-size:20px;
    height:50px;
    width:50px;
    color:black;
}
0

So you can use special characters by using  

You use the ampersand and the semicolon to indicate the special character.

Here is a list of a lot of the special characters you can use! Have fun. https://www.utexas.edu/learn/html/spchar.html

Chris Pena
  • 374
  • 1
  • 4
  • 10
0

You also could use &trade.

You can find more info about UTF-8 encoding here.

Thoaren
  • 194
  • 9
0

have you tried the htmlentities already?

string htmlentities ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = ini_get("default_charset") [, bool $double_encode = true ]]] )
0

I feel so silly. I checked into everything that you guys said in your answers and none of them were working for my situation. Finally I found out that my browser, Chrome, was set to the wrong settings in the font settings! It was set to "Western (Windows-1252)". I changed that to UTF-8 and it worked. Just go to chrome://settings/fonts in Chrome.

HighHopes
  • 2,014
  • 3
  • 23
  • 33