?
Solved

htmlentities not working properly on live server, only localhost

Posted on 2016-11-09
7
Medium Priority
?
89 Views
Last Modified: 2016-11-10
For some reason things that work on my localhost are not working on a live server. For instance:

$prod_name = htmlentities($row['prod_name'], ENT_QUOTES, "UTF-8");

Open in new window


works on my localhost but on the live server the title is showing funny characters like this � )

Does anybody have a clue why this might be?
0
Comment
Question by:Black Sulfur
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 41881019
Your character encoding has to be 100% consistent across all parts of the platform.  Check your HTML and PHP declarations and make sure they match.
https://www.experts-exchange.com/articles/11880/Unicode-and-Character-Collisions.html
0
 
LVL 1

Author Comment

by:Black Sulfur
ID: 41881089
A very interesting read, thanks!

Funny enough, I found the problem was actually caused by minifying my page. I used the GTmetrix minifier and that caused the problem. So, since I can't use that one, I don't suppose you know of a good one that minifies html and PHP. I suspect that is what broke it, the fact that I have PHP in there as well.

I tried this one:

https://htmlcompressor.com/compressor/

but I still get notified that I need to minify my HTML so obviously it isn't good enough.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 41881165
I'm never sure of the value you get from minifying PHP or HTML.  I can see minifying JavaScript, especially for big libraries like jQuery, and maybe CSS.  But the debugging problems you get from minification of PHP and HTML are just not worth the savings.  And in related matters, if the minifier changes something as basic as your character set encoding, you are doing the right thing to discard it completely.

Where / how do you get the notification that you need to minify your HTML?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:Black Sulfur
ID: 41881184
yeah, it isn't something I particularly want to do but I am trying to get a good score. I have managed to minify it without breaking it but Google and GTmetrix still say it isn't minified enough.

https://developers.google.com/speed/pagespeed/insights/

It says:

Compacting HTML code, including any inline JavaScript and CSS contained in it, can save many bytes of data and speed up download and parse times.
Minify HTML for the following resources to reduce their size by 811B (14% reduction).

Minifying http://mysite.com could save 811B (14% reduction) after compression.
0
 
LVL 1

Author Comment

by:Black Sulfur
ID: 41881187
P.S. I even minified my minify and I still get the message.
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 41881293
811B
Really?  You could transfer that a million times and not use as much time as we've spent on this question!  This is one of those things like milking a mouse -- no matter how much effort you put into the process, you just don't get much out.  I would recommend that you move on to something more important :-)  Check Peter Norvig's article (look for "Answers") and you can see where the center-of-gravity rests in some computer applications.  TL;DR there are a lot of things not worth optimizing!
http://norvig.com/21-days.html

FWIW, here is my hastily created example showing the places you probably want to use UTF-8.  
<?php // demo/utf8_example.php
/**
 * Making things work with UTF-8
 *
 * http://php.net/manual/en/function.mb-internal-encoding.php
 * http://php.net/manual/en/function.mb-regex-encoding.php
 * http://php.net/manual/en/function.mb-http-output.php#114843

 * http://php.net/manual/en/function.mysql-set-charset.php
 * http://php.net/manual/en/mysqli.set-charset.php
 * http://php.net/manual/en/ref.pdo-mysql.connection.php
 *
 * http://www.w3schools.com/TAgs/att_meta_charset.asp
 *
 * https://www.experts-exchange.com/articles/11880/Unicode-and-Character-Collisions.html
 * https://www.experts-exchange.com/articles/12335/PHP-and-MySQLi-Table-Maintenance.html
 */
error_reporting(E_ALL);


// MAKE SURE THAT PHP WORKS WITH UTF-8
mb_internal_encoding('UTF-8');
mb_regex_encoding('UTF-8');
mb_http_output('UTF-8');


// MAKE SURE THAT MySQL WORKS WITH UTF-8 (DEPRECATED)
mysql_set_charset('utf8mb4');

// MAKE SURE THAT MySQLi WORKS WITH UTF-8
$mysqli = new mysqli('localhost', 'username', 'password', 'test');
$mysqli->set_charset("utf8mb4");

// MAKE SURE THAT PDO WORKS WITH UTF-8 (RELEASE-DEPENDENT)
$pdo = new PDO("mysql:host=localhost;dbname=test;charset=utf8mb4", 'username', 'password');


// END OF PHP, LOOK AT HTML
?>
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>

<!-- MAKE SURE THAT HTML WORKS WITH UTF-8 -->
<meta charset="utf-8" />

</head>
<!-- etc etc ... -->

Open in new window

1
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 41882980
We've gotten a lot of questions about Google Pagespeed.  Some of their suggestions are worth following, some are not, and some are doable only when you own your own servers and wrote your own server code.  I rarely if ever minify any code.  

On sites where a lot of images are downloaded, I may enable 'gzip' compression.  That is a negotiation between the browser and the server.  Other than enabling it, it is not something that you do.  The server estimates whether it will take longer to compress it than to just send it.  A file with only 5800 bytes is not likely to be compressed.

Another thing I almost never do is set expiration dates for image, CSS, and JavaScript files.  My customers change those files way too often for that to be a good idea.
1

Featured Post

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question