Charset converting to question mark with diamond even though utf-8 - php

I am using a back end that uses ckeditor. There is nothing changed in the config.js so it is automatically converting french carachters with accents to the html entities.
So if i type é and check the ckeditor source i see é
The database table this field corresponds to is utf8_general_ci
The page charset is: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
so when I load the front end I receive the following:
�
If I type the é into the ckeditor source, it displays correctly on the page as it is not converting it to the html entity.
now if I turn off the coversion in the ckeditor config.js by: config.entities = false;
Then type the é and check the ckeditor source, it stays as é so I thought this would work,
However when loading the front end I get the error:
Parse error: syntax error, unexpected T_STRING in C:\wamp\www\site\includes\functions\clean_code.php(162) : eval()'d code on line 34
I can paste the clean_code.php code here but I think it is important to keep unchanged for the whole site. So I am kind of stuck. What can I do?
EDIT:
Ok so I tracked it down to a modification which was echoing the description with the following methods:
echo stripslashes( tep_sanitize_html( html_entity_decode( stripslashes( $product_info[ 'products_description' ] ) ) ) );
The vanilla way to do this is:
<?php echo stripslashes($product_info['products_description']); ?>
So I'm not sure why the developer of this addon decide to use the sanitize html method as well as the decode. but removing them and changing it back to the original way works.

These are two questions, so two answers:
The only logical answer to your problem displaying �, is that somewhere along the line, you are not correctly storing this as UTF-8 and it did get converted to something else.
The second problem, (fatal error in eval()'d code.) You should post the code that's triggering this error and preferably not even use eval for anything remotely important. Especially not dynamic eval() code, which you appear to be doing.

Related

CodeIgniter UTF-8 encoding issue

The Issue
I've been having some trouble with what I think is a UTF-8 encoding issue where posts are not being saved to my database.
The issue occurs when a user copy and pastes text from MS Word. There seems to be a particular combination of characters causing this issue (I've not found any other variations which cause the same issue yet):
% b
% B
This means that, when I var_dump() my input I get:
string(5) "70�ck"
Instead of:
string(5) "70% back"
Edit: The database error I get is:
Incorrect string value: '\xBAck an...' for column [...]
What I've tried
I'm using the Summernote JS plugin. I've tried a different plugin (WYSIHTML5) and I've tried with no plugin at all. I've tried pasting the clipboard text as plain text. I've even got an onPaste callback on the summernote which strips all the stupid encoding/styling from MS Word (which is summernote specific issue I think).
Unfortunately I've not been able to get anywhere with searching 'encoding issue "% b"' and variations thereof... but I would presume that the combination of characters above is somehow getting translated into a character that is unsupported by the database...
Database is MySQL 5.7.10 and I'm using utf8_general_ci collation on all columns.
I've set the charset to UTF-8 within CodeIgniter: $config['charset'] = 'UTF-8';
Within CodeIgniter's database config I've specified 'char_set' => 'uft8', 'dbcollat' => 'utf8_general_ci'
The page's meta tag is set to use utf-8: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
The form has the accept-charset="utf-8" attribute
Update: I've also tried the solution suggested in this question
I think I've done all the usual troubleshooting and I'm a bit stuck. Does anyone know why this specific combination of characters causes issue? Perhaps I'm wrong and it's not an encoding issue at all? Does anyone have any other ideas?
You should look into doing more on the front-end side. Try setting the encoding on the form, as most browsers should then only send UTF-8 to your server
<form ... accept-charset="UTF-8">
...
</form>
See this answer for more detail
Also, if you are using an editor, check out Quill, which allows pasting from word.

Why does my browser display the encoded html entity (e.g. &amp;amp;amp;)?

I have a php page that displays customer's input, which I saved in mysql database. When the input is loaded, some html characters are displayed wrongly.
For example this url:
http://www.greenbook.club/shopjerry/index.php/014101201323
You can see that the browser actually displays & amp; not just &.
I tried to use htmlspecialchars_decode or html_entity_decode, but seems no impact.
The code is really basic, just:
<?php echo $description ?>
////I also tried this, but no difference
<?php echo html_entity_decode($description) ?>
Can someone help?
I'd be looking at how this data is being saved. It appears that it's being encoded each time it's being saved without being decoded.
If you look at the rogue codes ie can&amp;amp;#39;t which is originally the word can't.
On the first save the single quote in can't would be getting turned into '
On the Second save that would then turn into &#39; then &amp;#39 and so on for each save.
SO the issue is with the process of saving the content from the editor into the Database. The content is being encoded when saved to the DB from the Editor but not decoded when loaded back from the DB into the editor.

Getting rid of HTML entities in a web title generated in PHP

I have a website with the content management system GetSimple which is written in PHP. I edited it as I needed, however, in the header, this is what is supposed to be there:
<title><?php get_page_clean_title(); ?> - <?php get_site_name(); ?></title>
The problem is that I am Czech and I have to use special characters (á, é, í, ó, ú, ů, ě, š etc.) and if you opened my website and saw the source code, you would see this:
<title>Tomáš Janeček - osobní web - Tom**áš** Janeček | Personal Website</title>
Instead of "Tomáš Janeček - osobní web - Tom*áš* Janeček | Personal Website".
What is bothering me are those HTML entities, which are only in the second part of the title. á stands for "á" and š stands for "š".
I know it's supposed not to hurt SEO, but I'm doing this to keep the code clear.
Is there a way to decode it or just change the get_site_name() to some better function that would have no problems with these extra characters? I don't want the entities in my code.
I think that it's not this concrete .php file that should be edited to make it as I want it to be, however, I hope it could be solved somehow simply in this file.
The CMS includes tens of .php files and I'm not sure what should I search for. I've looked for some code with PHP entities in "suspicious" files but I found nothing that helped me.
If you need it, the whole CMS can be downloaded here
Thanks for your help in advance.
Edit1:// --------------------------------------------------------------------------------------
Of course I have this meta included.
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
And no, I don't use any database. That will come with studying Joomla! :)
I want to emphasize that the title has 2 parts - get_page_clean_title() and get_site_name(), both of them include my whole name and only one displays it in the source code with HTML entities.
I have found the functions in another file:
The FIRST one is the one that doesn't put HTML entities into the source code - this is what I want from the second function lower.
function get_page_clean_title($echo=true) {
global $title;
$myVar = strip_tags(strip_decode($title));
if ($echo) {
echo $myVar;
} else {
return $myVar;
}
}
The SECOND function does what it is supposed to do, but it gives the output with HTML entities and that is the problem.
function get_site_name($echo=true) {
global $SITENAME;
$myVar = trim(stripslashes($SITENAME));
if ($echo) {
echo $myVar;
} else {
return $myVar;
}
}
Both of the functions above are in the same file.
I tried to replace the problematic function with the one working well with changing variables names to the right values, however, it stopped working at all :/
So, to conclude, the whole page is OK, there are no HTML entities except one place - the second half of the title with get_site_name function.
Furthermore, the problems is ONLY at the SOURCE CODE. The final displaying is okay.
Thanks for your replies so far, I'm glad for such fast and valuable replies. I really appreciate that.
I think you have a charset problem. If you want the special characters to display them in the right way, add
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
to your html/php file. Also check that your data is UTF-8 codified.
If you are getting your data from a MySQL database, check the columns use utf-8charset. Also set the charset for the connection with this query to ensure you are getting the data with the right codification.
set names utf8;
Tome, ensure that your *.php or database or whatever data is going off, is in UTF-8 and your meta charset on index is utf-8 also.
http://www.jakpsatweb.cz/cestina.html - Please visit this web for information about diacritics in html. You'll see the table of signs in each encoding.
How to save Russian characters in a UTF-8 encoded file

Changing servers, and getting SyntaxError: JSON.parse: unexpected character parsererror

I'm moving php code from one linux server to another, and the new one is producing rubbish.
In Firebug, the first result looks great, like normal json encoded values, and works.
The second result (new server) is preceded by "html" and "body" tags, a "p" tag, and then "quot;" instead of actual quotes around the data (sorry, I couldn't get the form to display all that), and throws an error.
In both cases, the code is the same, the output an array passed through json_encode.
Could this be a configuration error?
Thanks in advance.
John
Well, ultimately I added header('Content-type: application/json'); which removed the encoded html. I'd sure like to know why I had to do that.

Diaeresis show up as question marks when read from MSSQL database with PHP

I have a bit of PHP that gets data from a MSSQL database and saves it to an array:
while($row = mssql_fetch_array($dbquery, MSSQL_NUM))
{
$content = array(
'something' => $row[1],
'something_else' => $row[2]
// etcetera
);
}
(The reason why I write the data to an array like that is not relevant I think, but if you must know: it is because the data is parsed by ExpressionEngine (EECMS). The PHP code is part of a plugin I am developing and this is the easiest way to make the data available for use in ExpressionEngine tags.)
Some of the data in de MSSQL database contains punctuated characters, such as ë and é. The diaeresis (ë) are shown as question marks in the HTML. For instance, Cliënten is shown as Cli�nten.
The HTML is in UTF8: <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
I cannot change anything in the MSSQL database. What is the best way, preferably in PHP, to fix this?
When you see question marks like that, it means your browser is having trouble understanding what the character the question mark has replaced is supposed to represent. Most likely, it is expecting utf8 character encodings and is not getting them.
Try running something like this on your array (after it's built) and see if that helps:
$content = array_map('utf8_encode', $content);
Basically you want to run the utf8_encode() function on all the strings that come out of the database since apparently they are not encoded as such in the database.
You could also run the utf8_encode function immediately before you output each variable.
So something like:
<p><?php echo utf8_encode($content_row) ?></p>

Categories