Link to home
Start Free TrialLog in
Avatar of Crazy Horse
Crazy HorseFlag for South Africa

asked on

htmlentities not working properly on live server, only localhost

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?
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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
Avatar of Crazy Horse

ASKER

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.
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?
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.
P.S. I even minified my minify and I still get the message.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dave Baldwin
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.