encoding, php, tinymce ✓ check - php

I have a question on encoding. I have a TinyMCE editor and when you put in the source code part & check;" into it is converts it to a check symbol when it saves into a utf8_general_ci database. When I pull it out into PHP code how can I convert that checkmark back into code that the browser will understand on a utf-8 page? I messed around with htmlspecialchars_decode htmlentities html_entity_decode but couldn't get any of those to work with the checkmark maybe I am using them the wrong way. Thanks for the help.
TinyMCE: 4.5.3 (using defaults)
One Solution
I found out my code files were not encoded as UTF-8 which didn't allow me to copy/paste the actual check symbol to find/replace it. I changed the php file to UTF8 and I was able to str_replace the checks with the html entity version. I feel like there's a better way but this works for now.

Related

How to get degree symbol to show inside my table [duplicate]

I have a program which extracts GPS coordinates from metadata and imports the results onto a database. I then display the data using PHP on a webpage.
My problem - I've recently created a new template but for whatever reason, it is no longer showing the degrees symbol '°' but a '�'.
I just find it strange that it works with one template, but not the other?
I've tried changing fonts, but had no luck
See DEGREE CHARACTER.
Specifically, HTML Entity: °.
Check that you have the proper docstring and character encoding in both templates to make sure they are correct.
You can use:
utf8_encode('YOUR TEXT');
utf8_encode converts the string data from the ISO-8859-1 encoding to UTF-8.
Save your PHP file with UTF-8 encoding.
Serve your PHP file with charset=UTF-8.
Add a META-tag in your HTML with charset=UTF-8.
This will solve (almost) all of your unicode character problems.
When you input or pull the data from you database, use htmlentities()
you can find a good guide on this function a here http://php.net/manual/en/function.htmlentities.php
For degree celcius in html
<span>℃</span>

PHP strtotime() returns false on valid string

I can't get my head around the strtotime() function. I'm working with PHP 7.2.4 and want to parse some date and time strings. Following screenshot was taken in debug mode in PHPStorm:
As seen in the screenshot the grey date values show the same format. But exactly the one I programmatically parse is "suddenly" not valid. I've trimmed the string and everything is in UTF8.
Did I miss something?
The answer came instantly as wrote the question...
Answering my own question
Well, it just came to mind why it is not working: Microsoft uses UTF-8 with BOM by default if something is encoded in UTF8
I've created a file programmatically with C# and encoded it with System.Text.Encoding.UTF8. This encodes with BOM by default. So, for every beginner working with Microsoft Windows, be aware of the encoding of your files you parse later.
My problem was solved then by this solution:
Create Text File Without BOM
Hope this helps someone else.

Utf8 in html correct and php html output messed up

This issue is mind-boggling to me. I am facing the following situation. I wrote a website in html using the utf8 charset. Special characters are displayed as expected. Now I want to give out some php mysql results, so the easiest way is to create a php file, include the html code and then give out the results. However the html given out via the php file does not display the special characters correctly... it's not utf8
here is the html version: HTML
and here the exact copy in a php file: HTML VIA PHP
To close this question myself (because I feel rather stupid right now), the one who actually solved this is Marc B as his comments made me understand the process of text encoding.
After setting the header (Content Type and charset) as well as setting the meta tag in HTML I discovered, just like Marc suspected that my IDE had encoded the php file in another encoding than UTF8. Saving the file as UTF8 and replacing the messed up specialchars fixed my issue.
Please excuse this, I wasn't fully aware of what I was doing.

html content into a page

I need to pull the content from the database on the page, but some of this contents have the whole HTML page - with css, head, etc...
What would be the best way prevent having all htlm tags, scripts, css? Would iframe help here?
The most bothering thing is that I'm getting strange characters on the page: �
and as found out it is due to different encoding.
The site has utf-8 encoding and if the content contains different encoding, these signs come out and I cannot replace them.
The only thing it make them remove was to change my encoding, but this is not the real solution.
If someone could tell me how to remove them, would be really great.
Solution: with your help I checked encoding, but couldn't change it. I set names in mysql_query to UTF-8, and stripped unusefull tags. Now it seems ok.
Thanks to all of you.
I think you have no chance apart an ugly iframe. About encoding, you should check db encoding, connection encoding and convert as needed. Use iconv for full control over conversion, for example:
$html=iconv("UTF-8", "ISO-8859-15"."//TRANSLIT//IGNORE",$html]);
In this case, you're going to lose some characters not mapped in ISO-8859-15. Consider moving your whole site to UTF-8 encoding.
The � tags in fact might not be due to encoding, the problem might be the content that is stored in the database.
Check for double quotes like “ which are supposed to be ", more so if the data in the table was copy pasted.

How to get rid of � using php

I am pulling comments out of the database and have this, �, show up... how do I get rid of it? Is it because of whats in the database or how I'm showing it, I've tried using htmlspecialchars but doesn't work.
Please help
The problem lies with Character Encoding. If the character shows up fine in the database, but not on the page. Your page needs to be set to the same character encoding as the database. And vice a versa, if your page that posts to the database character encoding does not match, well it comes out weird.
I generally set my character encoding to UTF-8 for any type of posting fields, such as Comments / Posts. Most MySQL databases default to the latin charset. So you will need to modify that: http://yoonkit.blogspot.com/2006/03/mysql-charset-from-latin1-to-utf8.html
The HTML part can be done with a META tag: <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
or with PHP: header('Content-type: text/html; charset=utf-8'); (must be placed before any output.)
Hopefully that gets the ball rolling for you.
That happens when you have a character that your font doesn't know how to display. It shows up differently in every program, many Windows programs show it as a box, Firefox shows it as a questionmark in a diamond, other programs just use a plain question mark.
So you can use a newer display system, install a missing font (like if it's asian characters) or look to see if it's one or two characters that do this and just replace them with something visible.
It might be problem of the way you are storing the information in the database. If the encoding you were using didn't accept accents (à, ñ, î, ç...), then it stores them using weird symbols. Same happens to other language specific symbols. There is probably not a solution for what's already in the database, but you can still save the following inserts by changing the encoding type in mysql.
Cheers
Make sure your database UTF-8 (if it won't solve the problem make sure you specify your char-set while connecting to the database).
You can also encode / decode before entering data to your database.
I would suggest to go with htmlspecialchars() for encoding and htmlspecialchars_decode() for decoding.
Are you passing your charset in mysql_set_charset() with mysql_connect() ???
As others have said, check what your database encoding is. You could try using utf8_encode() or iconv() to convert your character encoding.
Check your code for errors. That's all one can really say considering that you have given us absolutely no details as to what you're doing.
Encoding problems are usually what cause that (are you converting from integers to characters?), so, you fix it by checking if you're converting things properly.

Categories