Reputation: 49
I am trying to print URL by using below:
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
It prints english URL fine but persian URL shows as below:
<link rel="canonical" href="https://www.example.com/8897-%D8%A7%DB%8C%D9%86%D9%B9%DB%8C%DA%A9-%D8%B1%D9%88%DB%8C%D9%86%D8%AC?lang=per"/>
Though the fields which are selected from database print in persian fine as below:
<title>اینٹیک روینج</title>
But when saved in php file (hard coded) turns into ?????? after saving.
snapshot of the is as below:
<title>اینٹیک روینج</title>
------> This is persian script what is selected from Database
<meta property="og:title" content="??????????">
-----> This is the persian script as above which was saved directly in this php file
<link rel="canonical" href="https://www.example.com/7657-%D8%A7%DB%8C%D9%86%D9%B9%DB%8C%DA%A9-%D8%B1%D9%88%DB%8C%D9%86%D8%AC?lang=per"/>
-----> This is he persian script what we capture from URL
Though to compare URL part with stored slug urldecode(auto_link($url)); works fine but I need to print them to show canonical URL
My Server host is RHEL 7 and I am using php 5.6, php.ini configuration is:
; PHP's default character set is set to UTF-8.
; http://php.net/default-charset
default_charset = "UTF-8"
For more information -> I have the setting in codeigniter 3 config.php as:
$config['charset'] = 'UTF-8';
I have declared below in html head:
Also in php I have declared
header('Content-Type: text/html; charset="utf-8"');
Upvotes: 0
Views: 130
Reputation: 418
To print your URL: https://www.example.com/8897-اینٹیک-روینج?lang=per
Use this
$url = urldecode((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
<link rel="canonical" href="<?=$url?>"/>
or you can do it in a single line
<link rel="canonical" href="<?=urldecode($url)?>"/>
Upvotes: 0