Solved

htmlentities not working properly on live server, only localhost

Posted on 2016-11-09
7
74 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 110

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 110

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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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 110

Accepted Solution

by:
Ray Paseur earned 500 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 83

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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

717 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