This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 3 years ago.
I searched for a lot of answers here but i still have a problem with the UTF8. "Special" letters doesn't appear in my browser.
I'm using:
php Designer 8
Wampserver 3.1.4_x86
MySQL 5.6
Navicat100_premium
I'm using Google
[
those "?" are all "çççççççç"
This is the beginning of the code:
<html>
<title> APPACDM </title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>
header('Content-type: text/html; charset=utf-8');
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
Everything looks in the wrong order to me. If this is a HTML page with embedded PHP try this:
<?php
header('Content-type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html>
<head>
<title> APPACDM </title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
Note: always set your PHP Header response before any HTML output. Always wrap PHP in PHP tags, not plain text as in your example.
See here: PHP Header command
Thanks,
Shaun.
If this data is queried from a database then you can do the following:
[PDO version]
$bdd->exec("set names utf8");
[MYSQLI version]
mysqli_set_charset($bdd, "utf8");
Related
Here is the title and link I used with the header, but I just get the word "Document" instead
<title>Chicken and Waffle | Local 360 | Gunyen</title>
<link rel="shortcut icon" type="image/png" href="images/gunyen%20logo%20dark.png">;
sample: https://gunyen.com/post/local360chknnwfl.php
What am I doing wrong?
Check your code again! This is the page source code I see in my browser:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="docsearch:language" content="en">
<meta name="docsearch:version" content="4.3">
<meta content="width=device-width, initial-scale=1" name="viewport">
<link rel="shortcut icon" type="image/png" href="images/gunyen%20logo%20dark.png"/>
<!--https://developers.google.com/search/reference/robots_meta_tag#directives-->
<!--<meta name="robots" content="index, follow, archive">-->
<meta name="robots" content="nofollow, noindex">
...
As you can see, there are 2 head blocks!
Most browsers will pick up favicon.ico from the root directory of the site without needing to be told; but they don't always update it with a new one right away.
However is a correct way to achieve your task with the name of favicon.ico:
<link rel='shortcut icon' type='image/x-icon' href='images/gunyen/logo/favicon.ico' />
Reference: https://stackoverflow.com/a/9943834/6366593
I have a problem right here. I'm developing a Webpage in PHP from scratch, currently I started with HTML and imported normalize.css in my index.view.php file, it looks like this:
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>AlfonsoIMa</title>
<link rel="stylesheet" href="css/normalize.css">
<script src="js/modernizr.js"></script>
<meta owner="Alfonso Izaguirre Martínez">
<meta author="Alfonso Izaguirre Martínez">
I'm using XAMPP and PHP7. I imported then refreshed my localhost and I didn't work. My code looks fine so, maybe the issue it's with XAMPP... Any solution?
You need to make sure that the css is called from the correct relative postition.
Try this instead:
<link rel="stylesheet" href="/css/normalize.css">
I'm using PHP to display people's information from a text file in an HTML table. Some of the text contains special characters (Köhler, François, František) and those characters are displayed as "�". I know this is because the encoding isn't set to charset="UTF-8", but I've set it using PHP's header() function as well as in the meta data in the <head>. In addition, I used Notepad to specifically save the file encoding as UTF-8.
When I inspect the page with
CTRL+Shift+i > Network > Headers
it includes "Content-Type:text/html; charset=UTF-8" under "Response Headers", so I think the browser should be getting the idea that the encoding is UTF-8.
What am I missing here?
Here's the code where I declare the charset in the PHP file
<?php
header('Content-Type:text/html; charset=UTF-8');
$ary_of_lines = file("customers.txt");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
....... more stuff .......
I've added the code
<meta name="viewport" content="width=device-width, initial-scale=1" />
to the HEAD of my webpage the Index.php at DuchyBrass.co.uk
It is on Line 6 of the source code, but the site runs on a bespoke CMS so the HEAD is defined in its own file and imported.
index.php
<!DOCTYPE html>
<html lang='en'>
<head>
<?php include 'app/common/head.php'; ?>
</head>
<body>
...
head.php
<title>Duchy Brass</title>
<meta charset="windows-1252" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="google-site-verification" content="QsU348JA47VLcAbTUic-Un90bVlGuVk3a9A34doxsvc" />
<link rel="stylesheet" type="text/css" href="css/style.css">
<link href='http://fonts.googleapis.com/css?family=Viga' rel='stylesheet' type='text/css'>
<link rel="icon" type="image/png" href="imgs/favicon.ico">
<link rel="canonical" href="http://www.duchybrass.co.uk" />
As far as the browser is concerned (I assume) that viewport tag is visible, but it is not seen by that Mobile SEO tool. Is this something to do with the CMS, loading the information too late, or is this a common issue that I should ignore?
The top of my Index page (using view page source from the browser) looks like
/ (page source)
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Duchy Brass</title>
<meta charset="windows-1252" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
...
TL;DR: clear caches and check if there is no content before head (ctrl+U)
I had a similar problem, in my case there were content being included trough PHP before my wordpress header call,
check it with Ctrl+U (see source) and be sure there is nothing before the
<!DOCTYPE html>
<html lang='en'>
<head>
if you change the code and it persists, check if you're using cache, you may have to clear caches of pages and files so the changes take effect before running another PageSpeed analysis
This is my first PHP-based web project. I have the web part of it working perfectly, but I'm having trouble with the mobile version. (Web hosting on godaddy linux)
What is the reason for my .php page not displaying? If I change it to .html, it works fine.
(I suspect the doctype, but not sure.)
Not sure if this code is necessary, but I'll leave out the body for the sake of space:
<?php include_once 'web/config.php'?>
<!DOCTYPE HTML>
<html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
"http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>About - Mobile</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="keywords" content="About - Mobile" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
</head>
config.php:
$link = mysqli_connect($server, $db_user, $db_pass);
mysqli_select_db($link, $database);
// -=-=-=-=-=-=-=[ Getting Variables ]=-=-=-=-=-=-=- //
$query = "SELECT * FROM `misc`";
$result = $link->query($query);
while($info = mysqli_fetch_array($result)){
// -=-=-=-=-=-=-=[ Variables ]=-=-=-=-=-=-=- //
$pickupTime = $info['pickupTime'];
$deliveryTime = $info['deliveryTime'];
$minDeliveryPrice = $info['minDeliveryPrice'];
$Gtitle = $info['Gtitle'];
$emailAccount = $info['emailAccount'];
$phone = $info['phone'];
$mailSubject= $info['mailSubject'];
$address = $info['address'];
$city = $info['city'];
$zipcode = $info['zipcode'];
$companyTel = $info['companyTel'];
$companyEmail = $info["companyEmail"];
$facebookLink = $info['facebookLink'];
$twitterLink = $info['twitterLink'];
$googleLink = $info['googleLink'];
$termsOfService = $info['termsOfService'];
}
?>
Thanks in advance!
PHP is executed at server side, as long as the PHP script renders valid HTML (this however doesn't seem the case), the phones won't care.
In case PHP code is received by a browser, something is wrong with the sever (for instance you didn't install PHP at server side, or the webserver doesn't know when to call PHP to generate a webpage)
A browser never receives the PHP code (otherwise it would be easy for instance to hijack databases since the PHP code has somehow the password).
PHP executes on the server, the client doesn't know it is talking to PHP. You need not change PHP code when targeting mobile platforms.
Your issue appears to be corrupt HTML
<?php include_once 'web/config.php'?>
We should probably see the config.php file to see what is happening in there.
<!DOCTYPE HTML>
<html>
Here you open an <HTML> tag.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
"http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
Here you open another <HTML> tag, this is an issue. You should only have one <HTML> tag as your outer node in the document.
<head>
<title>About - Mobile</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="keywords" content="About - Mobile" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
</head>
You do not close your <HTML> tags and you do not have a body to render.
Well since you said you posted only the head. Im just gonna fix your html to at least make it valid. And regarding the php, other answers explain why php doesn't matter when viewing websites in browsers
<?php include_once 'web/config.php'?>
<!DOCTYPE HTML>
<html>
<head>
<title>About - Mobile</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="keywords" content="About - Mobile" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
....
</body>
</html>
If this doesn't work, then I am guessing that this line of php <?php include_once 'web/config.php'?> is outputting something which is messing up the html or in other words, make it invalid, so try removing it and then tryAlso what do you mean its not displaying? Like nothing shows up? Or does it give an (http and or php) error?