Hi i am reading a string written in greek from a site with encoding “ISO-8859-7” on a php script running in cmd with the intention of adding parts of it in a mysql database. The problem is that before i add anything to the database i echo and there seems to be an encoding problem. I am attaching the relevant part of code.
$fil1=hitFormGet("http://www.topsites.gr/gr_domain_list/".$site->href);
$fil1=iconv("ISO-8859-7","UTF-8",$fil1);
$html1=str_get_html($fil1);
$data=$html1->find('td class="res3" table tbody table tbody tr');
echo "ttl".$data[4]->plaintext."\n";
and the output is
ttl Φιλοξενεί Site : Îαί
(It appears differently here too…)
Use UTF-8 whenever dealing with PHP and MySQL. Here is how I connect:
Additionally, in PHP < 5.3.6 set this additional attribute:
The integer
1002represents PDO::MYSQL_ATTR_INIT_COMMAND, however that command is broken in PHP < 5.3.1.Find below the original content of this answer, which is now outdated. This is the way to connect using the old
mysql_*functions, which are not recommended any more, with some other gibberish-preventing tips that were necessary at the time: