Japanese character encoding issue on web browser - php

When I query in MySQL then it returns in Japanese Character. An image is attached below.
But in browser its shown "????". An image is attached below.
Here I enclose my base.html code.
<!DOCTYPE HTML>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link media="screen" href="<?php echo $this->path_to('/common/css/import.css') ?>" type="text/css" rel="stylesheet" />
<script src="<?php echo $this->path_to('/common/js/jquery-2.1.0.min.js') ?>"></script>
<title><?php echo $this->v('page_title') ?></title>
</head>
<body>
<?php echo $this->part_of('body') ?>
</body>
</html>

Use mysqli_set_charset($db,'utf8'); in your dbconnection file. in my case $db is my connection variable

Related

Why my link in the head tag moved to the body?

I don't understand how this happen.
In my index.php, i require the page header.php :
<?php require("view/viewHeader.php");
Which contains this :
<!DOCTYPE html>
<html lang="fr">
<head>
<title>Mon systeme</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="manifest" href="manifest.json" />
<link rel="stylesheet" href="css/global.css" />
</head>
<body>
<div id="content">
So how i get this on the final page ?
link outside the head
The index.php has 165 lines, so i show you the beginning of the switch where the require call the viewHeader.php :
switch ($action) {
case 'ajout':
$menuTitre = "Ajout";
require("view/viewHeader.php");
require("view/viewMenuEnTete.php");
require("view/viewAjout.php");
require("view/viewFooter.php");
break;
Yes in the source it is alright
<div id="debug">ACTION: string(5) "ajout"
<br/>RECH: NULL
<br/><hr />POST<br/>array(1) {
["action"]=>
string(5) "ajout"
}
<hr /></div><!DOCTYPE html>
<html lang="fr">
<head>
<title>Mon systeme</title>
<link rel="manifest" href="manifest.json" />
<link rel="stylesheet" href="css/global.css" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<div id="content">
But the manifest is not detected. I thought there were a problem with the head mixed up.
I get rid of the small div in top, but it doesn't change anything :(
<!DOCTYPE html>
<html lang="fr">
<head>
<title>Mon systeme</title>
<link rel="manifest" href="manifest.json" />
<link rel="stylesheet" href="css/global.css" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<div id="content">

Heroku doesn't show anything

In my localhost the program runs well, but when I deploy it to heroku it doesn't show anything Like this and this is my folder This. Here my index code:
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="ina">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Lovanto Blog</title>
<link href="css/bootstrap-4.0.0.css" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet">
<link href="css/modal.css" rel="stylesheet">
<script src="js/jquery.min.js"></script>
<link rel="icon" href="icon.ico" type="image/x-icon" />
</head>
<body>
<?php
require 'vendor/autoload.php';
require 'cloudinary/vendor/autoload.php';
require 'cloudinary/config.php';
include 'conn.php';
include 'code/clock.php';
include 'view/header.php';
include 'view/body.php';
include 'view/footer.php';
?>
</body>
</html>
And this is my Procfile
web: vendor/bin/heroku-php-apache2

PHP - Require Adding Header Tags In Body

When I use pgp require it moves the head content on the included file into the body tags, I've explored questions somewhat related to my problem but none have solved my problem.
index.php:
<!DOCTYPE html>
<html>
<head></head>
<body></body>
</html>
<?php
require '/home/sethfreeman/public_html/subdomains/gwd/navigation/header/header.html';
?>
Included File:
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://sethjfreeman.com/subdomains/gwd/assets/css/header.css" type="text/css">
<link rel="stylesheet" href="http://sethjfreeman.com/subdomains/gwd/assets/libs/bootstrap/css/bootstrap.css" media="screen">
<link rel="stylesheet" href="http://sethjfreeman.com/subdomains/gwd/assets/libs/bootstrap/css/bootstrap-responsive.css" media="screen">
</head>
<body>
<div class="container"></div>
<script src="http://sethjfreeman.com/subdomains/gwd/assets/js/jquery-3.1.1.js"></script>
<script src="http://sethjfreeman.com/subdomains/gwd/assets/libs/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
Chrome Output:
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://sethjfreeman.com/subdomains/gwd/assets/css/header.css" type="text/css">
<link rel="stylesheet" href="http://sethjfreeman.com/subdomains/gwd/assets/libs/bootstrap/css/bootstrap.css" media="screen">
<link rel="stylesheet" href="http://sethjfreeman.com/subdomains/gwd/assets/libs/bootstrap/css/bootstrap-responsive.css" media="screen">
<div class="container"></div>
<script src="http://sethjfreeman.com/subdomains/gwd/assets/js/jquery-3.1.1.js"></script>
<script src="http://sethjfreeman.com/subdomains/gwd/assets/libs/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
"Require isn't smart. It's simply going to dump the contents of the required file where it's invoked. If you want some code in the head portion, put that in a separate file and require it in the correct place." - Major Productions LLC
To close this question.

i use a variable to echo the different title of different pages but i got an error

[i got an error on using a variable ( $page_title ) for echo the page title but it does not work and show me an error ]
[here is the code of header.php file]
<head>
<meta charset="UTF-8">
<title><?php echo $page_title; ?></title>
<meta name="description" content="sodalitesolutions">
<meta name="author" content="sodalitesolutions">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/bootstrap/css/bootstrap.css'); ?>">
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/font-awesome/css/font-awesome.css'); ?>">
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/style/slider.css'); ?>">
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/style/mystyle.css'); ?>">
</head>
[Error :: function: _error_handler]
Try to add this :
$this->data['title'] = 'test';
$this->load->view('view_name',$this->data);

Writing Head section with PHP

I'm converting a couple sites from HTML to PHP for dynamic elements and have been able to do so with the header and footer (using php include()). However, I'm confused on how to do the head section. This is what I have with plain HTML:
<head>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js">
</script>
<![endif]-->
<meta charset="UTF-8" />
<meta name="description" content="Liberty Resource Directory. The ultimate curated directory to find what you need."/>
<meta name="keywords" content="ethan glover, lrd, liberty resource directory"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href="stylesheets/lrdstylesheet.css" rel="stylesheet" media="screen">
<title>Liberty Resource Directory</title>
</head>
I can easily add the HTML5Shim script, meta charset, viewport (yes I will remove that max scale), and the stylesheet link.
Here's the problem:
How can I write the .php file in a way that I can pass an individual pages description, keywords and title to it? (That way I can put the entire above code in a php file and just include it on every page.)
Or will I simply have to exclude the description, keywords and title, and rewrite those parts every time?
Here's the answer: (Courtesy of Alejandro Arbiza)
head.php
<head>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js">
</script>
<![endif]-->
<meta charset="UTF-8" />
<meta name="description" content="<?php echo $description;?>"/>
<meta name="keywords" content="<?php echo $keywords;?>"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="../stylesheets/lrdstylesheet.css" rel="stylesheet" media="screen">
<title><?php echo $title;?></title>
</head>
index.html (to include above code)
<?php
$description="Liberty Resource Directory. The ultimate curated directory to find what you need.";
$keywords="ethan glover, lrd, liberty resource directory";
$title="Liberty Resource Directory";
include 'scripts/head.php';
?>
The final result:
http://libertyresourcedirectory.com/
You can use variables for the description and the keywords (or anything else you want for that matter). Then, when the time comes to construct the page, you would just set the variables with the corresponding values.
<head>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js">
</script>
<![endif]-->
<meta charset="UTF-8" />
<meta name="description" content="<?php echo $description; ?>"/>
<meta name="keywords" content="<?php echo $keywords; ?>"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href="stylesheets/lrdstylesheet.css" rel="stylesheet" media="screen">
<title>Liberty Resource Directory</title>
</head>
So, lets say you have page1.php and page2.php:
<?php
// page1.php
$description = "This is page one";
$keywords = "page one";
include 'header.php';
?>
<!-- Page content -->
<?php include 'footer.php'; ?>
and
<?php
// page2.php
$description = "This is page two";
$keywords = "page two";
include 'header.php';
?>
<!-- Page content -->
<?php include 'footer.php'; ?>
Of course, I am assuming here that the whole HTML header is inside the header.php file, that is including <html>, <head> and <body>.

Categories