php


mysql removed character encoding of text


I have to following code that runs fine when i run it on the browser and echo out the text, it displays proper arabic characters but the problem is when i save it into the mysql database, everything starts to garble up like in the screenshot below.
Here is the character encoding set on the database
and finally my code. I am totally confused and frustrated now on how to fix all this and I haven't found any solutions to this so far.
header('Content-Type: text/html; charset= Windows-1256');
require 'vendor/autoload.php';
use Goutte\Client;
$client = new Client();
$lebanonfiles = $client->request('GET', 'http://www.lebanonfiles.com');
$news_container = $lebanonfiles->filter('#mcs4_container .line');
$news_container->each(function($node) {
$temp = explode(' ',trim($node->text()));
$db = new MysqliDb (Array (
'host' => 'localhost',
'username' => 'root',
'password' => 'rolemodel',
'db'=> 'wade3',
'charset' => 'utf8_general_ci'));
$temp_time = date('Y-m-d H:i:s', strtotime($temp[0]));
$temp_text = utf8_decode(str_replace($temp[0]," ",$node->text()));
$temp_url = "http://www.lebanonfiles.com";
$data = Array(
'updated' => $temp_time,
'scraped_on' => $temp_time,
'link' =>$temp_url,
'title'=> $temp_text,
'feedsource' => 'lebanonfiles'
);
$db->insert('news', $data );
});
change charset to
'charset' => 'cp1256'
because client encoding must match the actual encoding of the data, which is windows-1256 as http header suggests.
remove the line
$temp_text = utf8_decode(str_replace($temp[0]," ",$node->text()));
because there is no utf to decode in your data.
as its been said, set charset to utf8.
make sure table charset is set to utf8 as well.
source charset on www.lebanonfiles.com is windows-1256.
replace utf8_decode with $temp_text = iconv("cp1256", "utf-8", str_replace($temp[0]," ",$node->text()));
that should work.
if you do not have iconv () enabled, try http://php.net/manual/en/function.mb-convert-encoding.php
Try to set the charset to UTF-8: mysqli_set_charset($yourConnection, "utf8");

Related Links

Php: Rewrite URL using web.config
Injecting class into controller - undefined variable
Facebook Total Shares count not working
How to reference $_SERVER['DOCUMENT_ROOT'] safely and efficiently in PHP
Why is only one result displaying in my table?
Accessing element in multi-dimensional array, php
HTML,PHP / smtp? Smartermail (don't receive any email) [duplicate]
mysql_num_rows result order
How to efficiently loop over large data in PHP?
Laravel blades performance
MySQL Select Group by show the latest post
GET and POST methods using Slim and Twig
Laravel 5 Redirect::to with multiple parameters
Same category multiple time in different level
Assign foreach variables
Render login form in my custom theme Wordpress

Categories

HOME
knockout.js
facebook-messenger
d3.js
haproxy
dafny
code-formatting
initialization
fogbugz
mithril.js
onvif
graphql-js
sympy
port
alljoyn
jquery-select2-4
spring-jpa
cuba-platform
heap-dump
closures
google-sites
cpu-usage
bluemix-mobile-services
gitkraken
ini
pyopencl
vuforia
crud
echosign
cube
ninject
basic-authentication
series
xcrun
nest
bean-validation
db2-luw
buildforge
orchardcms-1.8
eclipse-gmf
mv
variable-variables
gitolite
sspi
dredd
viewmodel
deployd
lightning-workbench
hibernate-ogm
wikimapia
allegro
boost-compute
msg
wininet
between
android-sdcard
odp.net-managed
adjacency-list
android-async-http
as3-api
ioctl
django-validation
servicestack-bsd
stack-smash
mousehover
highest
knife
uitest
vdm-sl
algebraixlib
angular-amd
phpredis
gflags
incron
nanomsg
lifetime
password-recovery
loginview
miglayout
nodeload
spring-social-linkedin
meteorite
vlab
codahale-metrics
delphi-xe4
itunes-sdk
struts2-json-plugin
zotonic
gamesalad
play2-mini
qt-mobility
aptitude
bass
android-2.1-eclair
explicit
resharper-5.1
raw-data
asdoc
getimagesize
rendering-engine
bindable-linq
webclient.uploaddata

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile